<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Requests\StoreEtablissementRequest;
use App\Http\Resources\EtablissementResource;
use App\Models\Etablissement;
use Illuminate\Http\Request;

class EtablissementController extends Controller
{
    public function index()
    {
        $etablissements = Etablissement::all();
        return EtablissementResource::collection($etablissements);
    }

    public function store(StoreEtablissementRequest $request)
    {
        $etablissement = Etablissement::create($request->validated());
        return new EtablissementResource($etablissement);
    }

    public function show(Etablissement $etablissement)
    {
        return new EtablissementResource($etablissement);
    }

    public function update(StoreEtablissementRequest $request, Etablissement $etablissement)
    {
        $etablissement->update($request->validated());
        return new EtablissementResource($etablissement);
    }

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