<?php

namespace App\Http\Controllers;

use App\Http\Requests\CategoriumStoreRequest;
use App\Http\Requests\CategoriumUpdateRequest;
use App\Http\Resources\CategoriumCollection;
use App\Http\Resources\CategoriumResource;
use App\Models\Categoria;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class CategoriaController extends Controller
{
    public function index(Request $request): CategoriumCollection
    {
        $categoria = Categorium::all();

        return new CategoriumCollection($categoria);
    }

    public function store(CategoriumStoreRequest $request): CategoriumResource
    {
        $categorium = Categorium::create($request->validated());

        return new CategoriumResource($categorium);
    }

    public function show(Request $request, Categorium $categorium): CategoriumResource
    {
        return new CategoriumResource($categorium);
    }

    public function update(CategoriumUpdateRequest $request, Categorium $categorium): CategoriumResource
    {
        $categorium->update($request->validated());

        return new CategoriumResource($categorium);
    }

    public function destroy(Request $request, Categorium $categorium): Response
    {
        $categorium->delete();

        return response()->noContent();
    }
}
