<?php

declare(strict_types=1);

/**
 * Web Routes
 *
 * Defines all routes for the Gmind Institute application.
 * Route format: $router->method('/path', 'Controller@method', [middleware])
 */

use App\Core\Router;

$router = new Router();

// ─── Middleware Registration ──────────────────────────────────────────────────

$router->addMiddleware('auth', function (): void {
    requireLogin();
});

$router->addMiddleware('admin', function (): void {
    requireAdmin();
});

// ─── Public Pages ────────────────────────────────────────────────────────────

$router->get('/', 'App\Controllers\HomeController@index');
$router->get('/about', 'App\Controllers\PageController@about');
$router->get('/pages/{slug}', 'App\Controllers\PageController@show');
$router->get('/courses', 'App\Controllers\CourseController@index');
$router->get('/courses/{id}', 'App\Controllers\CourseController@show');

// ─── Exams ───────────────────────────────────────────────────────────────────

$router->get('/exam', 'App\Controllers\ExamController@index');
$router->get('/exam/{id}', 'App\Controllers\ExamController@take');
$router->post('/exam/{id}/submit', 'App\Controllers\ExamController@submit');
$router->get('/exam/{id}/result', 'App\Controllers\ExamController@result');

// ─── Admission & Franchisee ──────────────────────────────────────────────────

$router->get('/admission', 'App\Controllers\AdmissionController@index');
$router->post('/admission', 'App\Controllers\AdmissionController@store');

$router->get('/franchisee', 'App\Controllers\FranchiseeController@index');
$router->post('/franchisee', 'App\Controllers\FranchiseeController@store');

// ─── Blog & News ─────────────────────────────────────────────────────────────

$router->get('/blog', 'App\Controllers\BlogController@index');
$router->get('/blog/{slug}', 'App\Controllers\BlogController@show');

$router->get('/news', 'App\Controllers\NewsController@index');
$router->get('/news/{slug}', 'App\Controllers\NewsController@show');

// ─── FAQ & Contact ───────────────────────────────────────────────────────────

$router->get('/faq', 'App\Controllers\FaqController@index');

$router->get('/contact', 'App\Controllers\ContactController@index');
$router->post('/contact', 'App\Controllers\ContactController@store');

// ─── Authentication ──────────────────────────────────────────────────────────

$router->get('/login', 'App\Controllers\AuthController@loginForm');
$router->post('/login', 'App\Controllers\AuthController@login');

$router->get('/register', 'App\Controllers\AuthController@registerForm');
$router->post('/register', 'App\Controllers\AuthController@register');

$router->post('/logout', 'App\Controllers\AuthController@logout');

// ─── Student Dashboard (requires auth) ───────────────────────────────────────

$router->get('/dashboard', 'App\Controllers\AuthController@dashboard', ['auth']);
$router->get('/profile', 'App\Controllers\AuthController@profile', ['auth']);
$router->post('/profile', 'App\Controllers\AuthController@updateProfile', ['auth']);

// ─── Admin Authentication ────────────────────────────────────────────────────

$router->get('/admin/login', 'Admin\Controllers\AdminAuthController@loginForm');
$router->post('/admin/login', 'Admin\Controllers\AdminAuthController@login');
$router->post('/admin/logout', 'Admin\Controllers\AdminAuthController@logout');

// ─── Admin Dashboard ─────────────────────────────────────────────────────────

$router->get('/admin', 'Admin\Controllers\DashboardController@index', ['auth', 'admin']);
$router->get('/admin/dashboard', 'Admin\Controllers\DashboardController@index', ['auth', 'admin']);

// ─── Admin — Sliders ─────────────────────────────────────────────────────────

$router->get('/admin/sliders', 'Admin\Controllers\AdminSliderController@index', ['auth', 'admin']);
$router->get('/admin/sliders/create', 'Admin\Controllers\AdminSliderController@create', ['auth', 'admin']);
$router->post('/admin/sliders', 'Admin\Controllers\AdminSliderController@store', ['auth', 'admin']);
$router->get('/admin/sliders/{id}/edit', 'Admin\Controllers\AdminSliderController@edit', ['auth', 'admin']);
$router->post('/admin/sliders/{id}', 'Admin\Controllers\AdminSliderController@update', ['auth', 'admin']);
$router->post('/admin/sliders/{id}/delete', 'Admin\Controllers\AdminSliderController@delete', ['auth', 'admin']);

// ─── Admin — Courses ─────────────────────────────────────────────────────────

$router->get('/admin/courses', 'Admin\Controllers\AdminCourseController@index', ['auth', 'admin']);
$router->get('/admin/courses/create', 'Admin\Controllers\AdminCourseController@create', ['auth', 'admin']);
$router->post('/admin/courses', 'Admin\Controllers\AdminCourseController@store', ['auth', 'admin']);
$router->get('/admin/courses/{id}/edit', 'Admin\Controllers\AdminCourseController@edit', ['auth', 'admin']);
$router->post('/admin/courses/{id}', 'Admin\Controllers\AdminCourseController@update', ['auth', 'admin']);
$router->post('/admin/courses/{id}/delete', 'Admin\Controllers\AdminCourseController@delete', ['auth', 'admin']);

// ─── Admin — Branches ────────────────────────────────────────────────────────

$router->get('/admin/branches', 'Admin\Controllers\AdminBranchController@index', ['auth', 'admin']);
$router->get('/admin/branches/create', 'Admin\Controllers\AdminBranchController@create', ['auth', 'admin']);
$router->post('/admin/branches', 'Admin\Controllers\AdminBranchController@store', ['auth', 'admin']);
$router->get('/admin/branches/{id}/edit', 'Admin\Controllers\AdminBranchController@edit', ['auth', 'admin']);
$router->post('/admin/branches/{id}', 'Admin\Controllers\AdminBranchController@update', ['auth', 'admin']);
$router->post('/admin/branches/{id}/delete', 'Admin\Controllers\AdminBranchController@delete', ['auth', 'admin']);

// ─── Admin — FAQs ────────────────────────────────────────────────────────────

$router->get('/admin/faqs', 'Admin\Controllers\AdminFaqController@index', ['auth', 'admin']);
$router->get('/admin/faqs/create', 'Admin\Controllers\AdminFaqController@create', ['auth', 'admin']);
$router->post('/admin/faqs', 'Admin\Controllers\AdminFaqController@store', ['auth', 'admin']);
$router->get('/admin/faqs/{id}/edit', 'Admin\Controllers\AdminFaqController@edit', ['auth', 'admin']);
$router->post('/admin/faqs/{id}', 'Admin\Controllers\AdminFaqController@update', ['auth', 'admin']);
$router->post('/admin/faqs/{id}/delete', 'Admin\Controllers\AdminFaqController@delete', ['auth', 'admin']);

// ─── Admin — Testimonials ────────────────────────────────────────────────────

$router->get('/admin/testimonials', 'Admin\Controllers\AdminTestimonialController@index', ['auth', 'admin']);
$router->post('/admin/testimonials/{id}/approve', 'Admin\Controllers\AdminTestimonialController@approve', ['auth', 'admin']);
$router->post('/admin/testimonials/{id}/reject', 'Admin\Controllers\AdminTestimonialController@reject', ['auth', 'admin']);
$router->post('/admin/testimonials/{id}/delete', 'Admin\Controllers\AdminTestimonialController@delete', ['auth', 'admin']);

// ─── Admin — Students ────────────────────────────────────────────────────────

$router->get('/admin/students', 'Admin\Controllers\AdminStudentController@index', ['auth', 'admin']);
$router->get('/admin/students/{id}', 'Admin\Controllers\AdminStudentController@show', ['auth', 'admin']);
$router->get('/admin/students/{id}/edit', 'Admin\Controllers\AdminStudentController@edit', ['auth', 'admin']);
$router->post('/admin/students/{id}', 'Admin\Controllers\AdminStudentController@update', ['auth', 'admin']);
$router->post('/admin/students/{id}/delete', 'Admin\Controllers\AdminStudentController@delete', ['auth', 'admin']);

// ─── Admin — Exams ───────────────────────────────────────────────────────────

$router->get('/admin/exams', 'Admin\Controllers\AdminExamController@index', ['auth', 'admin']);
$router->get('/admin/exams/create', 'Admin\Controllers\AdminExamController@create', ['auth', 'admin']);
$router->post('/admin/exams', 'Admin\Controllers\AdminExamController@store', ['auth', 'admin']);
$router->get('/admin/exams/{id}/edit', 'Admin\Controllers\AdminExamController@edit', ['auth', 'admin']);
$router->post('/admin/exams/{id}', 'Admin\Controllers\AdminExamController@update', ['auth', 'admin']);
$router->post('/admin/exams/{id}/delete', 'Admin\Controllers\AdminExamController@delete', ['auth', 'admin']);
$router->get('/admin/exams/{id}/questions', 'Admin\Controllers\AdminExamController@questions', ['auth', 'admin']);
$router->post('/admin/exams/{id}/questions', 'Admin\Controllers\AdminExamController@addQuestion', ['auth', 'admin']);
$router->post('/admin/exams/{id}/questions/{question_id}/delete', 'Admin\Controllers\AdminExamController@deleteQuestion', ['auth', 'admin']);

// ─── Admin — Settings ────────────────────────────────────────────────────────

$router->get('/admin/settings', 'Admin\Controllers\AdminSettingsController@index', ['auth', 'admin']);
$router->post('/admin/settings', 'Admin\Controllers\AdminSettingsController@update', ['auth', 'admin']);

// ─── Return the router instance ──────────────────────────────────────────────

return $router;
