<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Models\Chapter;
use Illuminate\Http\Request;

class ChapterController extends Controller
{
    public function index()
    {
        $chapters = Chapter::all();
        return response()->json($chapters);
    }

    public function show(Chapter $chapter)
    {
        return response()->json($chapter);
    }

    public function store(Request $request)
    {
        // Validation des données du formulaire

        $chapter = Chapter::create($request->all());

        return response()->json($chapter, 201);
    }

    public function update(Request $request, Chapter $chapter)
    {
        // Validation des données du formulaire

        $chapter->update($request->all());

        return response()->json($chapter, 200);
    }

    public function destroy(Chapter $chapter)
    {
        $chapter->delete();

        return response()->json(null, 204);
    }
}
