<?php

namespace App\Http\Controllers;

use App\Models\JourneeHypato;
use Illuminate\Http\Request;

class JourneeHypatoController extends Controller
{
    /**
     * Display a listing of the resource.
     */
    public function index()
    {
        $journees = JourneeHypato::all();
        return response()->json($journees);
    }

    /**
     * Show the form for creating a new resource.
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     */
    public function store(Request $request)
    {
        $validated = $request->validate([
            'image' => 'required|string',
            'event_date' => 'required|date',
            'title' => 'required|string|max:255',
            'date_param' => 'required|date',
        ]);

        $journee = JourneeHypato::create($validated);
        return response()->json(['message' => 'Event created successfully', 'data' => $journee], 201);

    }

    /**
     * Display the specified resource.
     */
    public function show(string $id)
    {
        $journee = JourneeHypato::findOrFail($id);
        return response()->json($journee);
    }

    /**
     * Show the form for editing the specified resource.
     */
    public function edit(string $id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     */
    public function update(Request $request, string $id)
    {
        $validated = $request->validate([
            'image' => 'string',
            'event_date' => 'date',
            'title' => 'string|max:255',
            'date_param' => 'date',
        ]);

        $journee = JourneeHypato::findOrFail($id);
        $journee->update($validated);
        return response()->json(['message' => 'Event updated successfully', 'data' => $journee]);

    }

    /**
     * Remove the specified resource from storage.
     */
    public function destroy(string $id)
    {
        $journee = JourneeHypato::findOrFail($id);
        $journee->delete();
        return response()->json(['message' => 'Event deleted successfully']);
    }
}
