<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\CourseController;
use App\Http\Controllers\TrainingClassController;
use App\Http\Controllers\StudentController;
use App\Http\Controllers\TeacherController;
use App\Http\Controllers\EnrollmentController;
use App\Http\Controllers\AttendanceSessionController;
use App\Http\Controllers\CertificateController;
use App\Http\Controllers\ClassScheduleController;
use App\Http\Controllers\AssessmentController;
use App\Http\Controllers\QuizController;
use App\Http\Controllers\StudentPortalController;
use App\Http\Controllers\ProfileController;

Route::get('/', function () {
    return redirect()->route('dashboard');
});

Route::middleware(['auth'])->group(function () {
    Route::get('/dashboard', [DashboardController::class, 'index'])
        ->name('dashboard');

    Route::resource('courses', CourseController::class);
    Route::resource('students', StudentController::class);
    Route::resource('teachers', TeacherController::class);
    Route::resource('enrollments', EnrollmentController::class);
    Route::resource('certificates', CertificateController::class);
    Route::resource('class-schedules', ClassScheduleController::class);

    Route::get('/classes', [TrainingClassController::class, 'index'])
        ->name('classes.index');
    Route::get('/classes/create', [TrainingClassController::class, 'create'])
        ->name('classes.create');
    Route::post('/classes', [TrainingClassController::class, 'store'])
        ->name('classes.store');
    Route::get('/classes/{trainingClass}', [TrainingClassController::class, 'show'])
        ->name('classes.show');
    Route::get('/classes/{trainingClass}/edit', [TrainingClassController::class, 'edit'])
        ->name('classes.edit');
    Route::put('/classes/{trainingClass}', [TrainingClassController::class, 'update'])
        ->name('classes.update');
    Route::delete('/classes/{trainingClass}', [TrainingClassController::class, 'destroy'])
        ->name('classes.destroy');

    Route::get('/attendance-sessions', [AttendanceSessionController::class, 'index'])
        ->name('attendance-sessions.index');
    Route::get('/attendance-sessions/create', [AttendanceSessionController::class, 'create'])
        ->name('attendance-sessions.create');
    Route::post('/attendance-sessions', [AttendanceSessionController::class, 'store'])
        ->name('attendance-sessions.store');
    Route::get('/attendance-sessions/{attendanceSession}', [AttendanceSessionController::class, 'show'])
        ->name('attendance-sessions.show');
    Route::post('/attendance-sessions/{attendanceSession}/save', [AttendanceSessionController::class, 'saveAttendance'])
        ->name('attendance-sessions.save');
    Route::get('/attendance-sessions/{attendanceSession}/edit', [AttendanceSessionController::class, 'edit'])
        ->name('attendance-sessions.edit');
    Route::put('/attendance-sessions/{attendanceSession}', [AttendanceSessionController::class, 'update'])
        ->name('attendance-sessions.update');
    Route::delete('/attendance-sessions/{attendanceSession}', [AttendanceSessionController::class, 'destroy'])
        ->name('attendance-sessions.destroy');

    Route::get('/assessments', [AssessmentController::class, 'index'])
        ->name('assessments.index');
    Route::get('/assessments/create', [AssessmentController::class, 'create'])
        ->name('assessments.create');
    Route::post('/assessments', [AssessmentController::class, 'store'])
        ->name('assessments.store');
    Route::get('/assessments/{assessment}', [AssessmentController::class, 'show'])
        ->name('assessments.show');
    Route::post('/assessments/{assessment}/save', [AssessmentController::class, 'saveResults'])
        ->name('assessments.save');
    Route::get('/assessments/{assessment}/edit', [AssessmentController::class, 'edit'])
        ->name('assessments.edit');
    Route::put('/assessments/{assessment}', [AssessmentController::class, 'update'])
        ->name('assessments.update');
    Route::delete('/assessments/{assessment}', [AssessmentController::class, 'destroy'])
        ->name('assessments.destroy');

    Route::get('/quizzes', [QuizController::class, 'index'])
        ->name('quizzes.index');
    Route::get('/quizzes/create', [QuizController::class, 'create'])
        ->name('quizzes.create');
    Route::post('/quizzes', [QuizController::class, 'store'])
        ->name('quizzes.store');
    Route::get('/quizzes/{quiz}', [QuizController::class, 'show'])
        ->name('quizzes.show');
    Route::get('/quizzes/{quiz}/edit', [QuizController::class, 'edit'])
        ->name('quizzes.edit');
    Route::put('/quizzes/{quiz}', [QuizController::class, 'update'])
        ->name('quizzes.update');
    Route::delete('/quizzes/{quiz}', [QuizController::class, 'destroy'])
        ->name('quizzes.destroy');

    Route::get('/quizzes/{quiz}/questions', [QuizController::class, 'questions'])
        ->name('quizzes.questions.index');
    Route::get('/quizzes/{quiz}/questions/create', [QuizController::class, 'createQuestion'])
        ->name('quizzes.questions.create');
    Route::post('/quizzes/{quiz}/questions', [QuizController::class, 'storeQuestion'])
        ->name('quizzes.questions.store');
    Route::get('/quiz-questions/{question}/edit', [QuizController::class, 'editQuestion'])
        ->name('quizzes.questions.edit');
    Route::put('/quiz-questions/{question}', [QuizController::class, 'updateQuestion'])
        ->name('quizzes.questions.update');
    Route::delete('/quiz-questions/{question}', [QuizController::class, 'destroyQuestion'])
        ->name('quizzes.questions.destroy');

    require __DIR__ . '/question_bank.php';

    Route::get('/student-portal', [StudentPortalController::class, 'index'])
        ->name('student-portal.index');

    Route::get('/student-portal/{enrollment}', [StudentPortalController::class, 'dashboard'])
        ->name('student-portal.dashboard');

    Route::get(
        '/student-portal/{enrollment}/quiz/{quiz}/intro',
        [StudentPortalController::class, 'examIntro']
    )->name('student-portal.quiz.intro');

    Route::post(
        '/student-portal/{enrollment}/quiz/{quiz}/start',
        [StudentPortalController::class, 'startExam']
    )->name('student-portal.quiz.start');

    Route::get(
        '/student-portal/{enrollment}/quiz/{quiz}',
        [StudentPortalController::class, 'take']
    )->name('student-portal.quiz.take');

    Route::post(
        '/student-portal/{enrollment}/quiz/{quiz}',
        [StudentPortalController::class, 'submit']
    )->name('student-portal.quiz.submit');

    Route::get(
        '/student-portal/{enrollment}/result/{attempt}',
        [StudentPortalController::class, 'result']
    )->name('student-portal.quiz.result');

    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');
});

require __DIR__ . '/auth.php';
