<?php

namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Requests\StoreAnneeRequest;
use App\Http\Resources\AnneeResource;
use App\Models\Annee;
use Illuminate\Http\Request;

class AnneeController extends Controller
{
    public function index()
    {
        $annees = Annee::all();
        return AnneeResource::collection($annees);
    }

    public function store(StoreAnneeRequest $request)
    {
        $annee = Annee::create($request->validated());
        return new AnneeResource($annee);
    }

    public function show(Annee $annee)
    {
        return new AnneeResource($annee);
    }

    public function update(StoreAnneeRequest $request, Annee $annee)
    {
        $annee->update($request->validated());
        return new AnneeResource($annee);
    }

    public function destroy(Annee $annee)
    {
        $annee->delete();
        return response()->json(['message' => 'Annee supprimé'], 200);
    }
}
