<?php

namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Requests\StoreMoughataaRequest;
use App\Http\Resources\MoughataaResource;
use App\Models\Moughataa;
use Illuminate\Http\Request;

class MoughataaController extends Controller
{
    public function index()
    {
        $moughataas = Moughataa::all();
        return MoughataaResource::collection($moughataas);
    }

    public function store(StoreMoughataaRequest $request)
    {
        $moughataa = Moughataa::create($request->validated());
        return new MoughataaResource($moughataa);
    }

    public function show(Moughataa $moughataa)
    {
        return new MoughataaResource($moughataa);
    }

    public function update(StoreMoughataaRequest $request, Moughataa $moughataa)
    {
        $moughataa->update($request->validated());
        return new MoughataaResource($moughataa);
    }

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