<?php

namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Requests\StoreAxeRequest;
use App\Http\Resources\AxeResource;
use App\Models\Axe;
use Illuminate\Http\Request;

class AxeController extends Controller
{
    /**
     * Display a listing of the resource.
     */
    public function index()
    {
        //
        $axes = Axe::all();
        return AxeResource::collection($axes);
    }

    public function store(StoreAxeRequest $request)
    {
        $axe = Axe::create($request->validated());
        return new AxeResource($axe);
    }

    public function show(Axe $axe)
    {
        return new AxeResource($axe);
    }

    public function update(StoreAxeRequest $request, Axe $axe)
    {
        $axe->update($request->validated());
        return new AxeResource($axe);
    }

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