<?php

declare(strict_types=1);

use App\Http\Controllers\Auth\SocialiteController;
use App\Http\Controllers\LandingController;
use App\Http\Controllers\ScreeningController;
use App\Http\Controllers\SessionController;
use Illuminate\Support\Facades\Route;

// Landing page (public)
Route::get('/', [LandingController::class, 'index'])->name('landing');
Route::get('/disclaimer', [LandingController::class, 'disclaimer'])->name('disclaimer');

// Authentication routes
Route::get('/login', [SocialiteController::class, 'redirect'])->name('login');
Route::get('/auth/callback', [SocialiteController::class, 'callback']);
Route::post('/logout', [SocialiteController::class, 'logout'])->name('logout')->middleware('auth');

// Questionnaire routes (authenticated)
Route::middleware('auth')->missing(fn () => redirect('/'))->group(function () {
    // Screening routes
    Route::post('/screening', [ScreeningController::class, 'store'])->name('screening.store');
    Route::get('/screening/{screening}', [ScreeningController::class, 'show'])->name('screening.show');
    Route::put('/screening/{screening}', [ScreeningController::class, 'update'])->name('screening.update');
    Route::get('/screening/{screening}/result', [ScreeningController::class, 'result'])->name('screening.result');

    // Session routes (with history encryption)
    Route::middleware('encrypt.history')->group(function () {
        Route::post('/sessions', [SessionController::class, 'store'])->name('sessions.store');
        Route::get('/sessions/{session}', [SessionController::class, 'show'])->name('sessions.show');
        Route::put('/sessions/{session}', [SessionController::class, 'update'])->name('sessions.update');
        Route::get('/sessions/{session}/result', [SessionController::class, 'result'])->name('sessions.result');
        Route::get('/sessions/{session}/pdf', [SessionController::class, 'pdf'])->name('sessions.pdf');
    });
});

// Dev auto-login route
Route::get('/login-for-testing', function () {
    $user = \App\Models\User::where('email', 'jonathan.van.rij@agerion.nl')->first();

    auth()->login($user);

    return redirect('/');
});
