<?php

namespace App\Http\Controllers\Api\Advisories;

use App\Http\Controllers\Controller;
use App\Models\Advisories\AdvisoryCompany;
use App\Transformers\Advisories\AdvisoryCompanyTransformer;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class AdvisoryCompaniesController extends Controller {
    protected AdvisoryCompany $model;

    public function __construct(AdvisoryCompany $model) {
        $this->model = $model;
    }

    public function index(Request $request): JsonResponse {
        $query = $this->model->query();
        $paginator = $query->paginate(config('app.pagination_limit'));
        return fractal($paginator, new AdvisoryCompanyTransformer())->respond();
    }

    public function show(Request $request, $id): JsonResponse {
        $model = $this->model->byUuid($id)->firstOrFail();
        return fractal($model, new AdvisoryCompanyTransformer())->respond();
    }

    public function store(Request $request): void {
    }

    public function update(Request $request, $uuid): void {
    }

    public function destroy(Request $request, $uuid): JsonResponse {
        $model = $this->model->byUuid($uuid)->firstOrFail();
        $model->advisoryMembers()->delete();
        $model->delete();
        return response()->json(null, 204);
    }


}
