<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Http\Resources\PackageResource;
use App\Models\Package;
use Illuminate\Http\Request;

class PackageApiController extends Controller
{
    public function index(Request $request)
    {
        $packages = Package::query()
            ->active()
            ->with('company')
            ->when($request->filled('company_id'), fn ($q) => $q->where('company_id', $request->company_id))
            ->when($request->filled('service_type'), fn ($q) => $q->where('service_type', $request->service_type))
            ->paginate($request->integer('per_page', 20));

        return PackageResource::collection($packages);
    }

    public function show(Package $package)
    {
        return new PackageResource($package->load('company'));
    }
}
