<?php

namespace App\Http\Controllers\Api\Localization;

use App\Http\Controllers\Controller;
use App\Models\Localization\Locale;
use App\Transformers\Localization\LocaleTransformer;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class LocalesController extends Controller {
    protected Locale $model;

    public function __construct(Locale $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 LocaleTransformer())->respond();
    }

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


    public function menu(Request $request): JsonResponse {
        return fractal($this->model->query()->enabled()->get(), new LocaleTransformer())->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->delete();
        return response()->json(null, 204);
    }

}
