<?php

namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Requests\StoreTypeEncadrementRequest;
use App\Http\Resources\TypeEncadrementResource;
use App\Models\TypeEncadrement;
use Illuminate\Http\Request;

class TypeEncadrementController extends Controller
{
    public function index()
    {
        $typeEncadrements = TypeEncadrement::all();
        return TypeEncadrementResource::collection($typeEncadrements);
    }

    public function store(StoreTypeEncadrementRequest $request)
    {
        $typeEncadrement = TypeEncadrement::create($request->validated());
        return new TypeEncadrementResource($typeEncadrement);
    }

    public function show(TypeEncadrement $typeEncadrement)
    {
        return new TypeEncadrementResource($typeEncadrement);
    }

    public function update(StoreTypeEncadrementRequest $request, TypeEncadrement $typeEncadrement)
    {
        $typeEncadrement->update($request->validated());
        return new TypeEncadrementResource($typeEncadrement);
    }

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