<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use App\Models\Session;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;

final class SessionController extends Controller
{
    /**
     * Create a new session for the selected category.
     */
    public function store(Request $request): RedirectResponse
    {
        $session = Session::create([
            'user_id' => auth()->id(),
            'category_id' => $request->input('category_id'),
            'screening_id' => $request->input('screening_id'),
            'status' => 'in_progress',
        ]);

        return redirect()->route('sessions.show', $session);
    }

    /**
     * Display the session questionnaire with category.
     */
    public function show(Session $session): Response
    {
        $session->load('category');

        return Inertia::render('Session/Show', [
            'session' => $session,
        ]);
    }

    /**
     * Save session answers and redirect to result.
     */
    public function update(Request $request, Session $session): RedirectResponse
    {
        return redirect()->route('sessions.result', $session);
    }

    /**
     * Display the final session result.
     */
    public function result(Session $session): Response
    {
        return Inertia::render('Session/Result', [
            'session' => $session,
        ]);
    }
}
