<?php

namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Requests\StoreCycleRequest;
use App\Http\Resources\CycleResource;
use App\Models\Cycle;
use Illuminate\Http\Request;

class CycleController extends Controller
{
    public function index()
    {
        $cycles = Cycle::all();
        return CycleResource::collection($cycles);
    }

    public function store(StoreCycleRequest $request)
    {
        $cycle = Cycle::create($request->validated());
        return new CycleResource($cycle);
    }

    public function show(Cycle $cycle)
    {
        return new CycleResource($cycle);
    }

    public function update(StoreCycleRequest $request, Cycle $cycle)
    {
        $cycle->update($request->validated());
        return new CycleResource($cycle);
    }

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