<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Requests\StoreDisciplineRequest;
use App\Http\Resources\DisciplineResource;
use App\Models\Discipline;
use Illuminate\Http\Request;

class DisciplineController extends Controller
{
    public function index()
    {
        $disciplines = Discipline::all();
        return DisciplineResource::collection($disciplines);
    }

    public function store(StoreDisciplineRequest $request)
    {
        $discipline = Discipline::create($request->validated());
        return new DisciplineResource($discipline);
    }

    public function show(Discipline $discipline)
    {
        return new DisciplineResource($discipline);
    }

    public function update(StoreDisciplineRequest $request, Discipline $discipline)
    {
        $discipline->update($request->validated());
        return new DisciplineResource($discipline);
    }

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