<?php

use App\Http\Controllers\PdfController;
use App\Http\Controllers\PortalController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\SiiirExportController;
use App\Http\Controllers\TwoFactorController;
use App\Http\Middleware\PortalAccess;
use Illuminate\Support\Facades\Route;

Route::get('/', function () {
    return view('welcome');
});

Route::get('/dashboard', function () {
    $user = auth()->user();
    if ($user && $user->hasAnyRole(['parinte', 'elev'])) {
        return redirect()->route('portal.dashboard');
    }
    return view('dashboard');
})->middleware(['auth', 'verified'])->name('dashboard');

Route::middleware(['auth', PortalAccess::class])->prefix('portal')->group(function () {
    Route::get('/', [PortalController::class, 'dashboard'])->name('portal.dashboard');
    Route::get('/elev/{elev}', [PortalController::class, 'elev'])->name('portal.elev');
});

Route::middleware('auth')->group(function () {
    Route::get('/2fa/challenge', [TwoFactorController::class, 'challenge'])->name('2fa.challenge');
    Route::post('/2fa/verify', [TwoFactorController::class, 'verify'])->name('2fa.verify');

    Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
    Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');

    Route::get('/pdf/elev/{elev}', [PdfController::class, 'situatieElev'])->name('pdf.situatie-elev');
    Route::get('/pdf/clasa/{clasa}', [PdfController::class, 'catalogClasa'])->name('pdf.catalog-clasa');
    Route::get('/pdf/matricol/{clasa}', [PdfController::class, 'registruMatricol'])->name('pdf.registru-matricol');
    Route::get('/pdf/foaie-matricola/{elev}', [PdfController::class, 'foaieMatricola'])->name('pdf.foaie-matricola');
    Route::get('/pdf/adeverinta/{elev}', [PdfController::class, 'adeverinta'])->name('pdf.adeverinta');

    Route::get('/siiir/elevi/{clasa}', [SiiirExportController::class, 'exportElevi'])->name('siiir.elevi');
    Route::get('/siiir/situatii/{clasa}', [SiiirExportController::class, 'exportSituatii'])->name('siiir.situatii');
    Route::get('/siiir/csv/{clasa}', [SiiirExportController::class, 'exportCsv'])->name('siiir.csv');
});

require __DIR__.'/auth.php';
