<?php

namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Requests\StoreNiveauRequest;
use App\Http\Resources\NiveauResource;
use App\Models\Niveau;
use Illuminate\Http\Request;


class NiveauController extends Controller
{
    public function index()
    {
        $niveaus = Niveau::all();
        return NiveauResource::collection($niveaus);
    }

    public function store(StoreNiveauRequest $request)
    {
        $niveau = Niveau::create($request->validated());
        return new NiveauResource($niveau);
    }

    public function show(Niveau $niveau)
    {
        return new NiveauResource($niveau);
    }

    public function update(StoreNiveauRequest $request, Niveau $niveau)
    {
        $niveau->update($request->validated());
        return new NiveauResource($niveau);
    }

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