<?php

namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Requests\StoreRegionRequest;
use App\Http\Resources\RegionResource;
use App\Models\Region;
use Illuminate\Http\Request;

class RegionController extends Controller
{
    public function index()
    {
        $regions = Region::all();
        return RegionResource::collection($regions);
    }

    public function store(StoreRegionRequest $request)
    {
        $region = Region::create($request->validated());
        return new RegionResource($region);
    }

    public function show(Region $region)
    {
        return new RegionResource($region);
    }

    public function update(StoreRegionRequest $request, Region $region)
    {
        $region->update($request->validated());
        return new RegionResource($region);
    }

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