<?php

namespace Config;

use function CodeIgniter\view;
use CodeIgniter\Router\RouteCollection;
use App\Controllers\View\ExtraChargesController;

/** @var RouteCollection $routes */

// Create a new instance of our RouteCollection class.
$routes = Services::routes();

// Load the system's routing file first, so that the app and ENVIRONMENT
// can override as needed.
if (file_exists(SYSTEMPATH . 'Config/Routes.php')) {
    require SYSTEMPATH . 'Config/Routes.php';
}



/*
 * --------------------------------------------------------------------
 * Router Setup
 * --------------------------------------------------------------------
 */
$routes->setDefaultNamespace('App\Controllers');
$routes->setDefaultController('Home');
$routes->setDefaultMethod('index');
$routes->setTranslateURIDashes(false);
$routes->set404Override();
$routes->setAutoRoute(false);

/*
 * --------------------------------------------------------------------
 * Route Definitions
 * --------------------------------------------------------------------
 */

// We get a performance increase by specifying the default
// route since we don't have to scan directories.
// Define the routes

/*
 * --------------------------------------------------------------------
 * Proofread (LanguageTool proxy)
 * --------------------------------------------------------------------
 */
$routes->post('api/proofread', 'ProofreadController::check', ['filter' => 'auth']);
$routes->post('school-year/select', 'View\SchoolYearSelectionController::select', ['filter' => 'auth']);
$routes->post('school-year/reset', 'View\SchoolYearSelectionController::reset', ['filter' => 'auth']);

/*
 * --------------------------------------------------------------------
 * routes for View\UserController
 * --------------------------------------------------------------------
 */

$routes->get('user/confirm/(:segment)', 'View\UserController::setPassword/$1');
$routes->post('user/save_password', 'View\UserController::savePassword');
$routes->get('invalid_token', 'View\UserController::invalidToken');


$routes->get('/user/password_set_success', 'View\UserController::passwordSetSuccess');
// Route for roles and permissions
$routes->post('user/select_role', 'View\UserController::selectRole');


/*
 * --------------------------------------------------------------------
 * routes for View\RolePermissionController
 * --------------------------------------------------------------------
 */
// Role Permission Routes
//$routes->get('rolepermission', 'View\RolePermissionController::index');
$routes->get('rolepermission/assign_role', 'View\RolePermissionController::assignRole');
$routes->get('api/rolepermission/users', 'View\RolePermissionController::usersData');
$routes->get('api/rolepermission/roles', 'View\RolePermissionController::rolesData');
$routes->get('api/rolepermission/permissions', 'View\RolePermissionController::permissionsData');
$routes->post('rolepermission/save_role', 'View\RolePermissionController::saveRole');
$routes->get('rolepermission/list_roles', 'View\RolePermissionController::listRoles');

// Role Permission Management Routes
$routes->get('rolepermission/edit_role_permissions/(:num)', 'View\RolePermissionController::editRolePermissions/$1');
$routes->post('rolepermission/edit_role_permissions/(:num)', 'View\RolePermissionController::editRolePermissions/$1');

$routes->get('rolepermission/load_permissions/(:num)', 'View\RolePermissionController::loadPermissions/$1');
$routes->post('rolepermission/save_role_permissions/(:num)', 'View\RolePermissionController::saveRolePermissions/$1');

// Role Management Routes (CRUD)
$routes->get('rolepermission/roles', 'View\RolePermissionController::rolesList');
$routes->get('roles/add', 'View\RolePermissionController::addRole');
$routes->post('roles/store', 'View\RolePermissionController::storeRole');
$routes->get('roles/edit/(:num)', 'View\RolePermissionController::editRole/$1');
$routes->post('roles/update/(:num)', 'View\RolePermissionController::updateRole/$1');
$routes->delete('roles/delete/(:num)', 'View\RolePermissionController::deleteRole/$1');


$routes->get('help_center', 'View\PageController::helpCenter');

//Report cards
$routes->get('report-card/student/(:num)', 'View\ReportCardsController::generateSingleReport/$1');
$routes->get('report-card/class/(:num)', 'View\ReportCardsController::generateClassReport/$1');
$routes->get('printables_reports/report_card', 'View\ReportCardsController::report_card');
// Student score card
$routes->post('student/score-card', 'View\StudentController::scoreCard');
$routes->get('student/score-card', 'View\StudentController::scoreCardIndex');
$routes->get('student/score-card/list', 'View\StudentController::scoreCardList');
$routes->get('administrator/student-score-card', 'View\StudentController::scoreCardAdmin');
// API for report card meta (students, class sections, school years)
$routes->get('api/printables/report-card/meta', 'View\ReportCardsController::reportCardMeta', ['filter' => 'auth']);
$routes->get('api/printables/report-card/completeness', 'View\ReportCardsController::reportCardCompleteness', ['filter' => 'auth']);
$routes->get('api/printables/report-card/ack', 'View\ReportCardsController::reportCardAcknowledgement', ['filter' => 'auth']);

//Badges
$routes->get('printables_reports/badge_form', 'View\BadgesController::badgeForm');
$routes->post('badge', 'View\BadgesController::badge');
// Badge print tracking APIs
$routes->get('api/printables/badges/status', 'View\BadgesController::badgePrintStatus', ['filter' => 'auth']);
$routes->post('api/printables/badges/log', 'View\BadgesController::logBadgePrint', ['filter' => 'auth']);

//Stickers
$routes->get('printables_reports/sticker_form', 'View\StickersController::stickerForm');
$routes->post('printables_reports/stickers', 'View\StickersController::generateStickers');
$routes->get('printables_reports/stickers', 'View\StickersController::generateStickers');

// Preview counts (JSON)
$routes->get('stickers/preview', 'View\ClassPrepController::previewStickerCounts');

// Generate PDF (your existing controller)//
$routes->post('stickers/generate', 'View\StickersController::generateStickers');
// (optional: keep legacy path used by your manual form)
//$routes->post('printables_reports/stickers', 'View\StickersController::generateStickers');

// Class roster (JSON) for the table in the view
$routes->get('api/students/by_class/(:num)', 'View\ClassPrepController::studentsByClass/$1');


/*
$routes->group('session', function($routes) {
    $routes->get('get-timeout-config', 'SessionController::getTimeoutConfig');
    $routes->get('check-timeout', 'SessionController::checkTimeout');
    $routes->post('ping-activity', 'SessionController::pingActivity');
});

*/
/*
 * --------------------------------------------------------------------
 * routes for View\TeacherController
 * --------------------------------------------------------------------
 */

$routes->get('administrator/teachers', 'View\TeacherController::showTeachers');
$routes->get('administrator/teacher/create', 'View\TeacherController::create');
$routes->post('administrator/teacher/store', 'View\TeacherController::store');
$routes->get('administrator/teacher/edit/(:num)', 'View\TeacherController::edit/$1'); // Placeholder for numeric ID
$routes->post('administrator/teacher/update/(:num)', 'View\TeacherController::update/$1'); // Placeholder for numeric ID
$routes->get('administrator/teacher/delete/(:num)', 'View\TeacherController::delete/$1'); // Placeholder for numeric ID
$routes->get('administrator/teacher_class_assignment', 'View\TeacherController::teacherClassAssignment', ['filter' => 'auth:assign_class_teacher']);
$routes->post('administrator/delete_assignment', 'View\TeacherController::deleteAssignment');

$routes->post('assign_class_teacher', 'View\TeacherController::assignClassTeacher');
//$routes->post('assign_class_teacher', 'View\TeacherController::assignClassTeacher', ['filter' => 'auth']);

$routes->group('api/administrator/teacher-class', ['filter' => 'auth:assign_class_teacher'], static function ($routes) {
    $routes->get('assignments', 'View\TeacherController::teacherClassAssignmentsApi');
    $routes->post('assign', 'View\TeacherController::assignClassTeacherApi');
    $routes->post('delete', 'View\TeacherController::deleteAssignmentApi');
});

$routes->group('administrator/subject-curriculum', ['filter' => 'auth:update_curriculum'], static function ($routes) {
    $routes->get('', 'View\SubjectCurriculumController::index');
    $routes->post('save', 'View\SubjectCurriculumController::store');
    $routes->get('edit/(:num)', 'View\SubjectCurriculumController::edit/$1');
    $routes->post('update/(:num)', 'View\SubjectCurriculumController::update/$1');
    $routes->post('delete/(:num)', 'View\SubjectCurriculumController::delete/$1');
});

$routes->get('administrator/trophy',              'View\TrophyController::index',   ['filter' => 'auth:admin']);
$routes->get('administrator/trophy/winners',      'View\TrophyController::winners', ['filter' => 'auth:admin']);
$routes->get('administrator/trophy/final',        'View\TrophyController::final',   ['filter' => 'auth:admin']);

// Certificates
$routes->get('administrator/certificates',           'View\CertificateController::index',    ['filter' => 'auth:admin']);
$routes->get('administrator/certificates/csrf-token', 'View\CertificateController::csrfToken', ['filter' => 'auth:admin']);
$routes->post('administrator/certificates/generate', 'View\CertificateController::generate', ['filter' => 'auth:admin']);
$routes->get('administrator/certificates/log',       'View\CertificateController::auditLog',  ['filter' => 'auth:admin']);
$routes->get('administrator/certificates/reprint/(:any)', 'View\CertificateController::reprint/$1', ['filter' => 'auth:read']);
$routes->get('verify/(:segment)',                    'View\CertificateController::verify/$1');



/*
 * --------------------------------------------------------------------
 * routes for View\UserController
 * --------------------------------------------------------------------
 */
$routes->get('/user', 'View\UserController::index');
$routes->post('/user/store', 'View\UserController::store');
$routes->get('/thankyou', 'View\UserController::thankyou'); // Thank you page route
$routes->get('/', 'View\UserController::home'); // Home page route
$routes->get('/about', 'View\UserController::about'); // About page route
$routes->get('/classes', 'View\UserController::classes'); // Classes page route
$routes->get('/contact', 'View\UserController::contact'); // Contact Us page route
$routes->post('/user/login', 'AuthController::login');
$routes->post('api/login', 'AuthController::apiLogin');
$routes->get('/welcome_back', 'View\UserController::welcomeBack');

$routes->get('user/forgot_password', 'View\UserController::forgotPassword'); //display forgot password form
//$routes->post('user/forgot_password', 'View\UserController::processForgotPassword'); //process the password forgot request

$routes->get('login', 'AuthController::loginMask');
$routes->get(
    'user/login_activity',
    'View\UserController::loginActivity',
    ['filter' => 'auth:view_login_activity']
);
$routes->get(
    'api/login-activity',
    'View\UserController::loginActivityData',
    ['filter' => 'auth:view_login_activity']
);

//edit user info
// app/Config/Routes.php
$routes->get('user/user_list', 'View\UserController::userList', ['filter' => 'auth:read_user']);
$routes->get('api/users', 'View\UserController::userListData', ['filter' => 'auth:read_user']);

// POST-only endpoint for updates (ID is in hidden input)
$routes->post('user/update', 'View\UserController::updateUser', ['filter' => 'auth:edit_user']);


$routes->get('usr/password_reset_confirmation', 'View\UserController::passwordResetConfirmation');
$routes->post('/processForgotPassword', 'View\UserController::processForgotPassword');

$routes->get('select-role', 'AuthController::selectRole');
$routes->post('set-role', 'AuthController::setRole');


$routes->get('user/processResetPassword', 'View\UserController::processResetPassword');
$routes->post('user/processResetPassword', 'View\UserController::processResetPassword');
$routes->get('password_reset_confirmation', 'View\UserController::passwordResetConfirmation');
$routes->get('reset_password', 'View\UserController::resetPassword');

//$routes->get('/blocked', 'View\UserController::blocked');

$routes->get('confirm_authorized_user', 'View\AuthorizedUsersController::confirm');
$routes->get('set_authorized_user_password/(:num)', 'View\AuthorizedUsersController::setPassword/$1');
$routes->post('set_authorized_user_password/(:num)', 'View\AuthorizedUsersController::savePassword/$1');

$routes->post('assign_class_student', 'View\StudentController::assignClassStudent');
$routes->post('remove_class_student', 'View\StudentController::removeClassStudent');
$routes->post('administrator/remove_class_student', 'View\StudentController::removeClassStudent'); // alias to avoid 404s
// Auto distribute sections after parent enrollments (admin tool)
// Sections auto-distribution (admin)
$routes->get('administrator/sections/auto-distribute', 'View\StudentController::autoDistributePage');
$routes->post('administrator/sections/auto-distribute', 'View\StudentController::autoDistributeSections');
// Totals API for dashboard
$routes->get('administrator/sections/promotion-totals', 'View\StudentController::promotionTotalsApi');


$routes->get('refunds/list', 'View\RefundController::listRefunds', ['filter' => 'auth:view_invoice|view_financial_reports|administrator|administrative staff|principal']);
$routes->post('refunds/request', 'View\RefundController::requestRefund', ['filter' => 'auth:create_invoice|view_financial_reports|administrator|administrative staff|principal,create']);
$routes->post('refunds/approve/(:num)', 'View\RefundController::approveRefund/$1', ['filter' => 'auth:update_invoice|view_financial_reports|administrator|administrative staff|principal,update']);
$routes->post('refunds/pay/(:num)', 'View\RefundController::payRefund/$1', ['filter' => 'auth:update_invoice|view_financial_reports|administrator|administrative staff|principal,update']);
$routes->post('refunds/updateStatus/(:num)', 'View\RefundController::updateStatus/$1', ['filter' => 'auth:update_invoice|view_financial_reports|administrator|administrative staff|principal,update']);
$routes->post('refunds/processRefunds', 'View\RefundController::processRefunds', ['filter' => 'auth:update_invoice|view_financial_reports|administrator|administrative staff|principal,update']);
$routes->post('refunds/updateStatus', 'View\RefundController::updateStatus', ['filter' => 'auth:update_invoice|view_financial_reports|administrator|administrative staff|principal,update']);
$routes->post('refunds/updatePayment', 'View\RefundController::updatePayment', ['filter' => 'auth:update_invoice|view_financial_reports|administrator|administrative staff|principal,update']);
$routes->post('refunds/recalculateOverpayments', 'View\RefundController::recalculateOverpayments', ['filter' => 'auth:update_invoice|view_financial_reports|administrator|administrative staff|principal,update']);
$routes->get('refunds/file/(:num)', 'View\RefundController::serveRefundFile/$1', ['filter' => 'auth:view_invoice|view_financial_reports|administrator|administrative staff|principal']);
$routes->get('refunds/file/(:num)/(:segment)', 'View\RefundController::serveRefundFile/$1/$2', ['filter' => 'auth:view_invoice|view_financial_reports|administrator|administrative staff|principal']);



$routes->get('class-prep', 'View\ClassPreparationController::index');
$routes->get('class-prep/print/(:segment)/(:segment)', 'View\ClassPreparationController::print/$1/$2');
$routes->post('class-prep/save-adjustment', 'View\ClassPreparationController::saveAdjustment');
// APIs for Class Prep
$routes->get('api/class-prep/list', 'View\ClassPreparationController::apiList', ['filter' => 'auth']);
$routes->post('api/class-prep/mark-printed', 'View\ClassPreparationController::apiMarkPrinted', ['filter' => 'auth']);

// UI helpers
$routes->get('ui/style', 'View\UiController::style');




//Timeout page after timeout
$routes->get('session/check-timeout', 'View\SessionTimeoutController::checkTimeout');
$routes->post('session/ping', 'View\SessionTimeoutController::pingActivity');


/*
 * --------------------------------------------------------------------
 * routes for View\ClassController
 * --------------------------------------------------------------------
 */
$routes->get('/administrator/classes', 'View\ClassController@index');
// Route to show the form for creating a new class
$routes->get('/administrator/classes/create', 'View\ClassController@create');
// Route to store a new class
$routes->post('/administrator/classes', 'View\ClassController@store');
// Route to show the form for editing a class
$routes->get('/administrator/classes/edit/{id}', 'View\ClassController@edit');
// Route to update a class
$routes->post('/administrator/classes/update/{id}', 'View\ClassController@update');
// Route to delete a class
$routes->get('/administrator/classes/delete/{id}', 'View\ClassController@destroy');
$routes->get('/class/list/(:num)', 'View\ClassController::classes/$1');


/*
 * --------------------------------------------------------------------
 * routes for View\ContactController
 * --------------------------------------------------------------------
 */
$routes->post('/contact_process', 'View\ContactController::processForm');
$routes->get('/parent/contact', 'View\ContactController::index');
$routes->post('/parent/contact/submit', 'View\ContactController::submit');


/*
 * --------------------------------------------------------------------
 * routes for Controller
 * --------------------------------------------------------------------
 */
$routes->get('/facility', 'View\FrontendController::facility');
$routes->get('/team', 'View\FrontendController::team');
$routes->get('/call-to-action', 'View\FrontendController::callToAction');
$routes->get('/testimonial', 'View\FrontendController::testimonial');
$routes->get('/notFound', 'View\FrontendController::notFound');


$routes->get('/', 'View\FrontendController::index');
$routes->get('/partials/fetch_user', 'View\FrontendController::fetchUser');

/*
 * --------------------------------------------------------------------
 * routes for View\ScoreController
 * --------------------------------------------------------------------
 */
// Route to show the form for creating a new score record
$routes->get('/administrator/scores/create', 'View\ScoreController::create');
// Route to store a new score record
$routes->post('/administrator/scores', 'View\ScoreController::store');
// Route to show the form for editing a score record
$routes->get('/administrator/scores/edit/{id}', 'View\ScoreController::edit');
// Route to update a score record
$routes->post('/administrator/scores/update/{id}', 'View\ScoreController::update');
// Route to delete a score record
$routes->get('/administrator/scores/delete/{id}', 'View\ScoreController::destroy');
$routes->get('/parent/scores', 'View\ScoreController::viewStudentScore');
$routes->get('parent/report-cards', 'ParentReportCardController::index', ['filter' => 'auth:parent']);
$routes->get('parent/report-cards/view/(:num)', 'ParentReportCardController::view/$1', ['filter' => 'auth:parent']);
$routes->post('parent/report-cards/sign/(:num)', 'ParentReportCardController::sign/$1', ['filter' => 'auth:parent']);




$routes->get('/teacher/scores', 'View\ScoreController::index');
$routes->get('/teacher/competition-scores', 'View\CompetitionScoresController::index', ['filter' => 'auth:teacher,teacher_assistant,teacher_dashboard,read']);
$routes->get('/teacher/competition-scores/(:num)', 'View\CompetitionScoresController::edit/$1', ['filter' => 'auth:teacher,teacher_assistant,teacher_dashboard,read']);
$routes->post('/teacher/competition-scores/(:num)', 'View\CompetitionScoresController::save/$1', ['filter' => 'auth:teacher,teacher_assistant,teacher_dashboard,read']);
$routes->get('/teacher/class_view', 'View\TeacherController::classView', ['filter' => 'auth:teacher_dashboard,read']);
$routes->get('no-classes', 'View\TeacherController::noClasses');

// Allow teacher and teacher_assistant roles
$routes->get('teacher/dashboard', 'View\TeacherController::dashboard', ['filter' => 'auth:teacher,teacher_assistant,teacher_dashboard,read']);
$routes->post('/teacher/switch-class', 'View\TeacherController::switchClass', ['filter' => 'auth:teacher,teacher_assistant,teacher_dashboard,read']);

$routes->get('/teacher/teacher_support', 'View\SupportController::supportTeacher', ['filter' => 'auth:teacher,teacher_assistant']);
$routes->get('/teacher/teacher_message', 'View\TeacherController::messageTeacher', ['filter' => 'auth:teacher,teacher_assistant']);
$routes->post('/teacher/teacher_message', 'View\TeacherController::messageTeacher', ['filter' => 'auth:teacher,teacher_assistant']);
$routes->get('/teacher/teacher_assignment', 'View\TeacherController::assignmentTeacher', ['filter' => 'auth:teacher,teacher_assistant']);
$routes->post('/teacher/teacher_assignment', 'View\TeacherController::assignmentTeacher', ['filter' => 'auth:teacher,teacher_assistant']);

$routes->get('/teacher/teacher_contactus', 'View\TeacherController::contactusTeacher', ['filter' => 'auth:teacher,teacher_assistant']);

$routes->get('/teacher/exam-drafts', 'View\ExamDraftController::teacherIndex', ['filter' => 'auth:teacher,teacher_assistant,teacher_dashboard,read']);
$routes->post('/teacher/exam-drafts', 'View\ExamDraftController::teacherStore', ['filter' => 'auth:teacher,teacher_assistant,teacher_dashboard,read']);
$routes->get('/teacher/exam-drafts/status', 'View\ExamDraftController::teacherStatusFeed', ['filter' => 'auth:teacher,teacher_assistant,teacher_dashboard,read']);



/*

 * --------------------------------------------------------------------

 * routes for Print Requests

 * --------------------------------------------------------------------

 */

$routes->get('teacher/print-requests', 'PrintRequests::teacher_index', ['filter' => 'auth:teacher,teacher_assistant']);

$routes->get('admin/print-requests', 'PrintRequests::admin_index', ['filter' => 'auth:admin']);

$routes->post('print-requests/create', 'PrintRequests::create', ['filter' => 'auth:teacher,teacher_assistant']);
$routes->post('print-requests/create-copy', 'PrintRequests::createCopy', ['filter' => 'auth:teacher,teacher_assistant']);
$routes->post('print-requests/copy/(:num)', 'PrintRequests::copy/$1', ['filter' => 'auth:teacher,teacher_assistant']);

$routes->post('print-requests/update/(:num)', 'PrintRequests::update/$1', ['filter' => 'auth:teacher,teacher_assistant,admin']);

$routes->post('print-requests/delete/(:num)', 'PrintRequests::delete/$1', ['filter' => 'auth:teacher,teacher_assistant,admin']);

$routes->get('print-requests/file/(:segment)', 'PrintRequests::serveFile/$1', ['filter' => 'auth:teacher,teacher_assistant,admin']);
$routes->get('print-requests/file/(:segment)/(:alpha)', 'PrintRequests::serveFile/$1/$2', ['filter' => 'auth:teacher,teacher_assistant,admin']);
$routes->get('uploads/print_requests/(:segment)', 'PrintRequests::serveFile/$1', ['filter' => 'auth:teacher,teacher_assistant,admin']);

$routes->get('exam-drafts/files/teacher/(:segment)', 'View\FilesController::examDraftTeacher/$1', ['filter' => 'auth:teacher,teacher_assistant,admin,administrator,principal']);
$routes->get('exam-drafts/files/final/(:segment)', 'View\FilesController::examDraftFinal/$1', ['filter' => 'auth:teacher,teacher_assistant,admin,administrator,principal']);







$routes->get('teacher/progress', 'ClassProgressController::history', ['filter' => 'auth:teacher,teacher_assistant']);
$routes->get('teacher/progress/submit', 'ClassProgressController::create', ['filter' => 'auth:teacher,teacher_assistant']);
$routes->post('teacher/progress/store', 'ClassProgressController::store', ['filter' => 'auth:teacher,teacher_assistant']);
$routes->get('teacher/progress/history', 'ClassProgressController::history', ['filter' => 'auth:teacher,teacher_assistant']);
$routes->get('teacher/progress/view/(:num)', 'ClassProgressController::view/$1', ['filter' => 'auth:teacher,teacher_assistant']);
$routes->get('teacher/progress/edit/(:num)', 'ClassProgressController::edit/$1', ['filter' => 'auth:teacher,teacher_assistant']);
$routes->post('teacher/progress/update/(:num)', 'ClassProgressController::update/$1', ['filter' => 'auth:teacher,teacher_assistant']);
$routes->get('teacher/progress/attachment/(:num)', 'ClassProgressController::attachment/$1', ['filter' => 'auth:teacher,teacher_assistant']);
$routes->get('teacher/progress/attachment-file/(:num)', 'ClassProgressController::attachmentFile/$1', ['filter' => 'auth:teacher,teacher_assistant']);
$routes->get('parent/progress', 'ParentProgressController::index', ['filter' => 'auth:parent']);
$routes->get('parent/progress/view/(:num)', 'ParentProgressController::view/$1', ['filter' => 'auth:parent']);
$routes->get('parent/progress/attachment/(:num)', 'ParentProgressController::attachment/$1', ['filter' => 'auth:parent']);
$routes->get('parent/progress/attachment-file/(:num)', 'ParentProgressController::attachmentFile/$1', ['filter' => 'auth:parent']);

$routes->get('admin/progress', 'AdminProgressController::index', ['filter' => 'auth:admin']);
$routes->get('admin/progress/view/(:num)', 'AdminProgressController::view/$1', ['filter' => 'auth:admin']);
$routes->get('admin/progress/attachment/(:num)', 'AdminProgressController::attachment/$1', ['filter' => 'auth:admin']);
$routes->get('admin/progress/attachment-file/(:num)', 'AdminProgressController::attachmentFile/$1', ['filter' => 'auth:admin']);

$routes->get('/teacher/calendar', 'View\SchoolCalendarController::calendarTeacherView');
$routes->get('/teacher/absence', 'View\TeacherController::absenceForm', ['filter' => 'auth:teacher,teacher_assistant']);
$routes->post('/teacher/absence', 'View\TeacherController::submitAbsence', ['filter' => 'auth:teacher,teacher_assistant']);

// Admin self-service staff absence (same features as teacher page)
$routes->get('/administrator/absence', 'View\AdministratorController::absenceFormAdmin', ['filter' => 'auth:admin']);
$routes->post('/administrator/absence', 'View\AdministratorController::submitAbsenceAdmin', ['filter' => 'auth:admin']);
$routes->get('/timeoff/notify/(:segment)', 'TimeOffNotificationController::notify/$1');
$routes->get('/teacher/showupdate_attendance', 'View\AttendanceController::showUpdateAttendanceForm');
$routes->post('/teacher/update_attendance', 'View\AttendanceController::updateAttendance');
$routes->post('/teacher/assignAttendance', 'View\AttendanceController::assignAttendance', ['as' => 'teacher.assignAttendance']);

$routes->get('administrator/calendar', 'View\SchoolCalendarController::calendarAdminView');


//quiz part
$routes->post('/teacher/updateQuizScores', 'View\QuizController::updateQuizscores');
$routes->get('/teacher/addNextQuizColumn', 'View\QuizController::addNextQuizColumn');
$routes->get('/teacher/addQuiz', 'View\QuizController::addQuiz');
$routes->post('/teacher/addQuiz', 'View\QuizController::addQuiz'); // change GET to POST
$routes->get('/teacher/addQuiz', 'View\QuizController::showAddQuizForm'); // for showing the form
// for saving quiz
$routes->post('/teacher/submit-scores-lock', 'View\ScoreController::submitScoresLock');


//homework part
$routes->post('/teacher/updateHomework', 'View\HomeworkController::updateHomeworkScores');
$routes->get('/teacher/addNextHomeworkColumn', 'View\HomeworkController::addNextHomeworkColumn');
$routes->get('/teacher/addHomework', 'View\HomeworkController::showHomework');
$routes->get('/teacher/index/(:num)', 'View\HomeworkController::index/$1', ['as' => 'viewHomework']);

//project part
$routes->get('/teacher/addProject', 'View\ProjectController::addProject');
$routes->post('/teacher/updateProject', 'View\ProjectController::updateProjectScores');
$routes->get('/teacher/addNextProjectColumn', 'View\ProjectController::addNextProjectColumn');

//Midterm part
$routes->get('/teacher/addMidtermExam', 'View\MidtermController::add');
$routes->post('/teacher/updateMidtermExamScores', 'View\MidtermController::update');
$routes->post('grading/updateMidtermExamScores', 'View\MidtermController::updateMngt');

// Final part for grading interface
$routes->post('grading/updateFinalExamScores', 'View\ScoreController::updateFinalExamScoresForGrading');


//Participation part
$routes->get('/teacher/addParticipation', 'View\ParticipationController::add');
$routes->post('/teacher/updateParticipationScore', 'View\ParticipationController::update');
$routes->post('grading/updateParticipationScore', 'View\ParticipationController::updateMngt');


$routes->get('grading/quiz/(:num)', 'View\QuizController::showQuizMngt/$1');
$routes->post('/grading/updateQuiz', 'View\QuizController::updateQuiz');

$routes->post('teacher/saveComments', 'View\ScoreCommentController::saveComments'); // or View\ScoreCommentController

$routes->post('grading/updateComments', 'View\ScoreCommentController::updateComments');
$routes->get('grading/comments', 'View\ScoreCommentController::viewCommentsMngt');
$routes->post('grading/update-placement-level', 'View\GradingController::updatePlacementLevel');
$routes->get('grading/placement', 'View\GradingController::placement', ['filter' => 'auth:read']);
$routes->post('grading/placement', 'View\GradingController::updatePlacementLevels', ['filter' => 'auth:read']);
$routes->post('grading/placement-all', 'View\GradingController::updatePlacementLevelsAll', ['filter' => 'auth:read']);
$routes->get('grading/placement/batch/(:num)', 'View\GradingController::editPlacementBatch/$1', ['filter' => 'auth:read']);
$routes->post('grading/placement/batch/(:num)', 'View\GradingController::updatePlacementBatch/$1', ['filter' => 'auth:read']);


$routes->match(['get', 'post'], 'grading/homework', 'View\HomeworkController::showHomeworkMngt', ['filter' => 'auth:read']);
// Homework tracking overview (management)
$routes->get('grading/homework-tracking', 'View\HomeworkTrackingController::index', ['filter' => 'auth:read']);
$routes->match(['get', 'post'], 'grading/quiz', 'View\QuizController::showQuizMngt');        // if you have them
$routes->match(['get', 'post'], 'grading/project', 'View\ProjectController::showProjectMngt');
$routes->match(['get', 'post'], 'grading/participation', 'View\ParticipationController::showParticipationMngt');
$routes->match(['get', 'post'], 'grading/midterm', 'View\MidtermController::showMidtermMngt');
$routes->match(['get', 'post'], 'grading/midterm', 'View\MidtermController::updateMngt');
$routes->match(['get', 'post'], 'grading/final', 'View\FinalController::showFinalMngt');

// Final Exam (teacher)
$routes->get('/teacher/addFinalExam', 'View\FinalController::add');
$routes->post('/teacher/updateFinalExamScores', 'View\ScoreController::updateFinalExamScores');

$routes->post('grading/updateHomework', 'View\HomeworkController::updateHomework');

$routes->get('grading/project/(:num)', 'View\ProjectController::showProjectMngt/$1');
$routes->post('grading/updateProject', 'View\ProjectController::updateProject');

$routes->get('grading/below-60', 'View\GradingController::belowSixty', ['filter' => 'auth:read']);
$routes->get('grading/below-60/email/edit', 'View\GradingController::editBelowSixtyEmail', ['filter' => 'auth:read']);
$routes->post('grading/below-60/email', 'View\GradingController::sendBelowSixtyEmail', ['filter' => 'auth:read']);
$routes->post('grading/below-60/status', 'View\GradingController::updateBelowSixtyStatus', ['filter' => 'auth:read']);
$routes->get('grading/below-60/schedule', 'View\GradingController::scheduleBelowSixty', ['filter' => 'auth:read']);
$routes->post('grading/below-60/schedule', 'View\GradingController::saveBelowSixtyMeeting', ['filter' => 'auth:read']);
$routes->get('grading/decisions', 'View\GradingController::allDecisions', ['filter' => 'auth:read']);
$routes->post('grading/decisions/generate', 'View\GradingController::generateAllDecisions', ['filter' => 'auth:read']);
$routes->get('grading/below-60/decisions', 'View\GradingController::belowSixtyDecisions', ['filter' => 'auth:read']);
$routes->post('grading/below-60/decisions/save', 'View\GradingController::saveBelowSixtyDecision', ['filter' => 'auth:read']);
$routes->get('grading/below-60/decisions/student-details', 'View\GradingController::studentDecisionDetails', ['filter' => 'auth:read']);
$routes->get(
    'grading/below-60/decisions/email/preview',
    'View\GradingController::previewBelowSixtyDecisionEmail',
    ['filter' => 'auth:read']
);

$routes->post(
    'grading/below-60/decisions/email',
    'View\GradingController::sendBelowSixtyDecisionEmail',
    ['filter' => 'auth:read']
);

// Final part
$routes->get('grading/(:segment)/(:num)/(:num)', 'View\GradingController::show/$1/$2/$3');
$routes->post('grading/update', 'View\GradingController::update');
$routes->get('grading', 'View\GradingController::grading');
$routes->post('grading/toggle-score-lock', 'View\GradingController::toggleScoreLock', ['filter' => 'auth:read']);
$routes->get('grading/toggle-score-lock', static function () {
    return 'GET route hit. Something is calling this route incorrectly.';
});
$routes->post('grading/lock-all-scores', 'View\GradingController::lockAllScores', ['filter' => 'auth:read']);
$routes->post('grading/release-scores', 'View\GradingController::toggleParentScoresRelease', ['filter' => 'auth:read']);
$routes->post('grading/refresh-semester-scores', 'View\GradingController::refreshSemesterScores', ['filter' => 'auth:read']);

// Event admin routes
$routes->get('administrator/events', 'View\EventController::index');
$routes->get('administrator/events/create', 'View\EventController::create'); // show create form
$routes->post('administrator/events/create', 'View\EventController::create'); // handle event create submission
// Route to show form and handle POST in same controller method
$routes->match(['get', 'post'], 'administrator/events/edit/(:num)', 'View\EventController::edit/$1');


$routes->post('administrator/events/delete/(:num)', 'View\EventController::delete/$1'); // handle delete
$routes->post('payment/event_charges', 'View\EventController::eventUpdate');

// Parent event participation
$routes->get('administrator/event-charges', 'View\EventController::eventShow');
$routes->get('administrator/event-charges/pdf', 'View\EventController::eventChargesPdf');
$routes->post('administrator/event-charges/remove/(:num)', 'View\EventController::removeCharge/$1');
$routes->post('administrator/event-charges/payment/(:num)', 'View\EventController::toggleEventPayment/$1');
$routes->post('administrator/event-charges/waiver/(:num)', 'View\EventController::toggleWaiverStatus/$1');
$routes->get('administrator/get-students-with-charges', 'View\EventController::getStudentsWithCharges');

$routes->get('parent/events', 'View\ParentController::parentEventPage', ['filter' => 'auth:parent']);
// parent event participation page
$routes->post('parent/updateParticipation', 'View\ParentController::updateParticipation'); // handle parent participation updates


// Web View Routes for Invoices
$routes->get('invoices/getByParent/(:num)', 'View\InvoiceController::getByParent/$1');
$routes->get('invoices/create', 'View\InvoiceController::create');
$routes->post('invoices/updateStatus/(:num)', 'View\InvoiceController::updateStatus/$1');

// app/Config/Routes.php

// app/Config/Routes.php
$routes->group('payment', ['filter' => 'auth'], static function ($routes) {
    // Read
    $routes->get('manual_pay', 'View\PaymentController::manualPaySearch', ['filter' => 'auth:view_invoice|view_payment|view_financial_reports|administrator|administrative staff|principal']);
    $routes->get('manual_pay_suggest', 'View\PaymentController::manualPaySuggest', ['filter' => 'auth:view_invoice|view_payment|view_financial_reports|administrator|administrative staff|principal']);

    // Create
    $routes->post('manual_pay', 'View\PaymentController::manualPayUpdate', ['filter' => 'auth:create_payment|create_invoice|view_financial_reports|administrator|administrative staff|principal,create']);

    // Update
    $routes->post('manual_pay_edit', 'View\PaymentController::manualPayEdit', ['filter' => 'auth:update_payment|update_invoice|view_financial_reports|administrator|administrative staff|principal,update']);
    $routes->post('manual_pay_update', 'View\PaymentController::manualPayUpdate', ['filter' => 'auth:create_payment|create_invoice|view_financial_reports|administrator|administrative staff|principal,create']);

    // Read (serve files)
    $routes->get('file/(:num)/(:segment)', 'View\PaymentController::servePaymentFile/$1/$2', ['filter' => 'auth:view_invoice|view_payment|view_financial_reports|administrator|administrative staff|principal']);
    $routes->get('file/(:num)', 'View\PaymentController::servePaymentFile/$1', ['filter' => 'auth:view_invoice|view_payment|view_financial_reports|administrator|administrative staff|principal']);
});



// Optional: if someone opens it in the browser via GET, redirect to the search page:
$routes->get('payment/manual_pay_update', function () {
    return redirect()->to(site_url('payment/manual_pay'));
});

/*
$routes->group('admin/charges', ['filter' => 'auth'], static function($routes) {
    $routes->get('/', 'ExtraChargesController::index');
    $routes->get('parents', 'ExtraChargesController::parentOptions'); // <-- for Select2
    $routes->post('store', 'ExtraChargesController::store');
    $routes->post('update/(:num)', 'ExtraChargesController::update/$1');
    $routes->post('void/(:num)', 'ExtraChargesController::void/$1');
});

*/

$routes->group('admin', ['filter' => 'auth'], static function ($routes) {
    $routes->group('charges', static function ($routes) {
        // Serve HTML page from ::page, keep ::index for API JSON
        $routes->get('/',        [ExtraChargesController::class, 'page']);
        $routes->get('parents',  [ExtraChargesController::class, 'parentOptions']);
        $routes->get('invoices', [ExtraChargesController::class, 'invoicesForParent']); // <-- AJAX endpoint
        $routes->get('list',     [ExtraChargesController::class, 'apiList']);
        $routes->post('store',   [ExtraChargesController::class, 'store']);
        $routes->post('update/(:num)', [ExtraChargesController::class, 'update/$1']);
        $routes->post('void/(:num)',   [ExtraChargesController::class, 'void/$1']);
        $routes->post('reverse/(:num)', [ExtraChargesController::class, 'reverse/$1']);
    });
});

//send emails to parents
$routes->group('admin', ['filter' => 'auth'], static function ($routes) {
    $routes->get('broadcast-email', 'View\BroadcastEmailController::index');
    $routes->post('broadcast-email/send', 'View\BroadcastEmailController::send');
});
$routes->post('admin/broadcast-email/upload-image', 'View\BroadcastEmailController::uploadImage');


$routes->get('payment/financial_report', 'View\FinancialController::financialReport', ['filter' => 'auth:view_financial_reports|view_invoice|administrator|administrative staff|principal']);
$routes->get('financial-report/financialReportSummary', 'View\FinancialController::financialReportSummary', ['filter' => 'auth:view_financial_reports|view_invoice|administrator|administrative staff|principal']);
$routes->get('financial-report/downloadSummaryCsv', 'View\FinancialController::downloadSummaryCsv', ['filter' => 'auth:view_financial_reports|view_invoice|administrator|administrative staff|principal']);
$routes->get('financial-report/downloadSummaryAllDetailsCsv', 'View\FinancialController::downloadSummaryAllDetailsCsv', ['filter' => 'auth:view_financial_reports|view_invoice|administrator|administrative staff|principal']);
$routes->get('payment/download_csv', 'View\FinancialController::downloadCsv', ['filter' => 'auth:view_financial_reports|view_invoice|administrator|administrative staff|principal']);
$routes->get('administrator/tuition-forecast', 'View\TuitionForecastController::index', ['filter' => 'auth:view_financial_reports|view_invoice|administrator|administrative staff|principal']);
$routes->post('administrator/tuition-forecast/calculate', 'View\TuitionForecastController::calculate', ['filter' => 'auth:view_financial_reports|view_invoice|administrator|administrative staff|principal']);
$routes->get('administrator/tuition-forecast/export', 'View\TuitionForecastController::exportCsv', ['filter' => 'auth:view_financial_reports|view_invoice|administrator|administrative staff|principal']);
$routes->get('reports/downloadFinancialReport', 'View\FinancialController::downloadFinancialReport');
// Financial APIs (JSON)
$routes->get('api/financial/report', 'View\FinancialController::financialReportData', ['filter' => 'auth']);
$routes->get('api/financial/summary', 'View\FinancialController::financialReportSummaryData', ['filter' => 'auth']);

// Unpaid parents (balance > 0) listing
$routes->get('payment/unpaid-parents', 'View\FinancialController::unpaidParents', ['filter' => 'auth:view_invoice']);
$routes->get('api/financial/unpaid-parents', 'View\FinancialController::unpaidParents', ['filter' => 'auth:view_invoice']);


$routes->get('expenses/index', 'View\ExpenseController::index', ['filter' => 'auth:view_financial_reports|administrator|administrative staff|principal']);
$routes->get('expenses/create', 'View\ExpenseController::create', ['filter' => 'auth:view_financial_reports|administrator|administrative staff|principal']);
$routes->post('expenses/store', 'View\ExpenseController::store', ['filter' => 'auth:view_financial_reports|administrator|administrative staff|principal,create']);
$routes->post('expenses/updateStatus', 'View\ExpenseController::updateStatus', ['filter' => 'auth:view_financial_reports|administrator|administrative staff|principal,update']);

$routes->get('reimbursements/index', 'View\ReimbursementController::index', ['filter' => 'auth:view_financial_reports|administrator|administrative staff|principal']);
$routes->get('reimbursements/create', 'View\ReimbursementController::create', ['filter' => 'auth:view_financial_reports|administrator|administrative staff|principal']);
$routes->post('reimbursements/store', 'View\ReimbursementController::store', ['filter' => 'auth:view_financial_reports|administrator|administrative staff|principal,create']);
$routes->get('reimbursements/under-processing', 'View\ReimbursementController::underProcessing', ['filter' => 'auth:view_financial_reports|administrator|administrative staff|principal']);
$routes->post('reimbursements/mark-donation', 'View\ReimbursementController::markDonation', ['filter' => 'auth:view_financial_reports|administrator|administrative staff|principal,update']);
$routes->post('reimbursements/batch/create', 'View\ReimbursementController::createBatch', ['filter' => 'auth:view_financial_reports|administrator|administrative staff|principal,create']);
$routes->post('reimbursements/batch/update', 'View\ReimbursementController::updateBatchAssignment', ['filter' => 'auth:view_financial_reports|administrator|administrative staff|principal,update']);
$routes->post('reimbursements/batch/lock', 'View\ReimbursementController::lockBatch', ['filter' => 'auth:view_financial_reports|administrator|administrative staff|principal,update']);
$routes->post('reimbursements/batch/admin-file/upload', 'View\ReimbursementController::uploadBatchAdminFile', ['filter' => 'auth:view_financial_reports|administrator|administrative staff|principal,update']);
$routes->get('reimbursements/batch/admin-file/(:segment)', 'View\ReimbursementController::serveAdminCheckFile/$1', ['filter' => 'auth:view_financial_reports|administrator|administrative staff|principal']);
$routes->get('reimbursements/batch/admin-file/(:segment)/(:segment)', 'View\ReimbursementController::serveAdminCheckFile/$1/$2', ['filter' => 'auth:view_financial_reports|administrator|administrative staff|principal']);
$routes->post('reimbursements/batch/send', 'View\ReimbursementController::sendBatchEmail', ['filter' => 'auth:view_financial_reports|administrator|administrative staff|principal,update']);
$routes->get('reimbursements/batch/export', 'View\ReimbursementController::exportBatch', ['filter' => 'auth:view_financial_reports|administrator|administrative staff|principal']);
$routes->post('reimbursements/process', 'View\ReimbursementController::process', ['filter' => 'auth:view_financial_reports|administrator|administrative staff|principal,update']);
$routes->get('reimbursements/export', 'View\ReimbursementController::export', ['filter' => 'auth:view_financial_reports|administrator|administrative staff|principal']);
$routes->get('reimbursements', 'View\ReimbursementController::index', ['filter' => 'auth:view_financial_reports|administrator|administrative staff|principal']);

// Health check (upload dirs + DB timezone columns)
$routes->get('admin/health', 'View\HealthController::index');

//Notifications
$routes->get('notifications/active', 'View\NotificationsController::listActive');
$routes->get('api/notifications/active', 'View\NotificationsController::activeNotificationsData');
$routes->get('notifications/deleted', 'View\NotificationsController::listDeleted');
$routes->get('api/notifications/deleted', 'View\NotificationsController::deletedNotificationsData');
$routes->post('notifications/restore/(:num)', 'View\NotificationsController::restore/$1');
//$routes->post('notifications/restore/(:num)', 'View\NotificationsController::restore/$1');
//$routes->get('notifications/mark-read/(:num)', 'View\NotificationsController::markAsRead/$1');
$routes->get('/administrator/notifications_alerts', 'View\AdministratorController::notificationsAlerts');
$routes->post('/administrator/notifications_alerts/save', 'View\AdministratorController::saveNotificationSubjects');
$routes->get('/administrator/print-notifications', 'View\AdministratorController::printNotificationRecipients');
$routes->post('/administrator/print-notifications/save', 'View\AdministratorController::savePrintNotificationRecipients');


$routes->get(
    'invoice_payment/invoice_management',
    'View\InvoiceController::index',
    ['filter' => 'auth:view_invoice']
);
$routes->get(
    'api/invoices/management',
    'View\InvoiceController::managementData',
    ['filter' => 'auth:view_invoice']
);
$routes->get(
    'api/invoices/by-parent/(:num)',
    'View\InvoiceController::getByParentAPI/$1',
    ['filter' => 'auth:view_invoice']
);
$routes->post(
    'api/invoices/generate',
    'View\InvoiceController::generateInvoice',
    ['filter' => 'auth:create_invoice']
);
$routes->post(
    'api/invoices/update-status/(:num)',
    'View\InvoiceController::updateStatusAPI/$1',
    ['filter' => 'auth:update_invoice,update']
);
$routes->post(
    'invoices/generate',
    'View\InvoiceController::generateInvoice',
    ['filter' => 'auth:create_invoice']
);
$routes->get('/parent/invoice_payment', 'View\InvoiceController::invoicePayment'); // Route for invoice payment page
$routes->get('invoice/pay/(:num)', 'View\InvoiceController::payInvoice/$1'); // Route for paying the invoice
$routes->get('invoices', 'View\InvoiceController::index'); // Default route for invoices
$routes->get('invoices/(:any)', 'View\InvoiceController::index/$1'); // Route with school year filter
$routes->get('invoices/recalculate/(:segment)', 'View\PaymentController::recalculateInvoiceByNumber/$1', ['filter' => 'auth:update_invoice']); // Recalculate invoice totals/balance
$routes->get('invoice/pdf/(:num)', 'View\InvoiceController::generatePdfInvoice/$1', ['filter' => 'auth:invoice_pdf,read']);


// Web View Routes for Payments
$routes->get('payments/getByParent/(:num)', 'View\PaymentController::getByParent/$1');
$routes->get('payments/create', 'View\PaymentController::create');
$routes->post('payments/updateBalance/(:num)', 'View\PaymentController::updateBalance/$1');

// Routes for payment pages
$routes->get('payments/view/(:num)', 'View\PaymentController::viewPayment/$1');
$routes->get('payment/get_enrolled_students/(:num)', 'View\PaymentController::getEnrolledStudents/$1', ['filter' => 'auth:view_invoice|view_payment|view_financial_reports|administrator|administrative staff|principal']);

// Payment Notification Management
$routes->get('payment/notification_management', 'View\PaymentNotificationController::index', ['filter' => 'auth:view_invoice']);
// API: Send payment reminders (single parent or bulk)
$routes->post('api/payments/notifications/send', 'View\PaymentNotificationController::send', ['filter' => 'auth:view_invoice']);

/*
 * --------------------------------------------------------------------
 * routes for View\AdministratorController
 * --------------------------------------------------------------------
 */
$routes->get('administrator/classes', 'View\AdministratorController::classes');
$routes->get('administrator/subjects', 'View\AdministratorController::subjects');
$routes->get('administrator/reports', 'View\AdministratorController::reports');
$routes->get('administrator/teacher-dashboard', 'View\AdministratorController::teacherDashboard');
$routes->get('/administrator/contact_information', 'View\AdministratorController::contactInformation');
$routes->get('administrator/search', 'View\AdministratorController::userSearch');
$routes->get('administrator/userSearch', 'View\AdministratorController::userSearch');

$routes->get('/administrator/student_profiles', 'View\AdministratorController::studentProfiles');
$routes->get('/administrator/parent_profiles', 'View\AdministratorController::parentProfiles');
$routes->get('/administrator/removed_students', 'View\StudentController::removedStudents');
$routes->get('/administrator/teacher-submissions', 'View\AdministratorController::teacherSubmissionsReport', ['filter' => 'auth:admin']);
$routes->post('/administrator/teacher-submissions/notify', 'View\AdministratorController::sendTeacherSubmissionNotifications', ['filter' => 'auth:admin']);
$routes->get('/administrator/exam-drafts', 'View\ExamDraftController::adminIndex', ['filter' => 'auth:admin']);
$routes->post('/administrator/exam-drafts/review', 'View\ExamDraftController::adminReview', ['filter' => 'auth:admin']);
$routes->post('/administrator/exam-drafts/upload-legacy', 'View\ExamDraftController::adminUploadLegacy', ['filter' => 'auth:admin']);
$routes->get('/principal/exam-drafts', 'View\ExamDraftController::principalIndex', ['filter' => 'auth:admin']);
$routes->post('/principal/exam-drafts/review', 'View\ExamDraftController::principalReview', ['filter' => 'auth:admin']);
$routes->post('/principal/exam-drafts/upload-legacy', 'View\ExamDraftController::principalUploadLegacy', ['filter' => 'auth:admin']);

/*
 * --------------------------------------------------------------------
 * routes for View\MessagesController
 * --------------------------------------------------------------------
 */
$routes->get('messages', 'View\MessagesController::index');
$routes->post('messages/send', 'View\MessagesController::send');
$routes->get('/messages/inbox', 'View\MessagesController::inbox');
$routes->get('/messages/sent', 'View\MessagesController::sent');
$routes->get('/messages/drafts', 'View\MessagesController::drafts');
$routes->get('/messages/trash', 'View\MessagesController::trash');

// Additional routes for handling actions like viewing, sending, deleting, etc.
$routes->get('/messages/view/(:num)', 'View\MessagesController::view/$1');
$routes->post('/messages/send', 'View\MessagesController::send');
$routes->get('/messages/delete/(:num)', 'View\MessagesController::delete/$1');
$routes->get('/messages/deletePermanent/(:num)', 'View\MessagesController::deletePermanent/$1');
$routes->get('/messages/restore/(:num)', 'View\MessagesController::restore/$1');
$routes->get('/messages/getRecipients/(:any)', 'View\MessagesController::getRecipients/$1');

/*
 * --------------------------------------------------------------------
 * routes for View\AttendanceController
 * --------------------------------------------------------------------
 */
$routes->get('/teacher/showupdate_attendance', 'View\AttendanceController::showUpdateAttendanceForm');
$routes->post('/teacher/update_attendance', 'View\AttendanceController::updateAttendance');
$routes->post('/teacher/assignAttendance', 'View\AttendanceController::assignAttendance', ['as' => 'teacher.assignAttendance']);

// Add this line in your Routes.php
$routes->post('attendance/update', 'View\AttendanceController::updateAttendanceManagement');
$routes->get('/administrator/daily_attendance', 'View\AttendanceController::listAttendance');
$routes->get('/administrator/daily_attendance/analysis', 'View\AttendanceController::dailyAttendanceAnalysis');
// API: daily attendance data (admin)
$routes->get('api/admin/daily-attendance', 'View\AttendanceController::dailyData');
// Admin attendance: add one entry
$routes->post(
    'administrator/attendance/add-entry',
    'View\AttendanceController::adminAddEntry',
    ['filter' => 'auth:attendance_add_entry,create'] // <— permission:name , crudAction
);

// Late slip printing (preview + print)
// No auth filter here to match existing attendance endpoints and avoid blocking users without role mappings
$routes->match(['get', 'post'], 'slips/preview', 'View\SlipPrinterController::preview');
$routes->match(['get', 'post'], 'slips/print',   'View\SlipPrinterController::print');

// Late slip logs listing and reprint
$routes->get('administrator/late_slips', 'View\LateSlipLogsController::index');
$routes->post('administrator/late_slips/reprint/(:num)', 'View\SlipPrinterController::reprint/$1');


$routes->group('api/time', ['namespace' => 'App\Controllers\Api'], static function ($routes) {
    $routes->get('now', 'TimeController::now');
    $routes->post('convert', 'TimeController::convert');
});


/*
 * --------------------------------------------------------------------
 * routes for View\SchoolCalendarController
 * --------------------------------------------------------------------
 */
$routes->group('administrator', ['namespace' => 'App\Controllers'], function ($routes) {
    $routes->get('calendar_view', 'View\SchoolCalendarController::index');
    $routes->get('calendar_edit/(:num)', 'View\SchoolCalendarController::edit/$1');
    $routes->get('calendar_delete/(:num)', 'View\SchoolCalendarController::delete/$1');
    $routes->post('calendar_delete/(:num)', 'View\SchoolCalendarController::delete/$1');
    $routes->get('update/(:num)', 'View\SchoolCalendarController::update/$1');
    $routes->post('update/(:num)', 'View\SchoolCalendarController::update/$1');
    $routes->get('calendar_add_event', 'View\SchoolCalendarController::addEvent');
    $routes->post('calendar_add_event', 'View\SchoolCalendarController::addEvent');
});


/*
 * --------------------------------------------------------------------
 * routes for Parent Pages
 * --------------------------------------------------------------------
*/
$routes->get('/parent/add_second_parent', 'View\ParentController::addSecondParent');
$routes->get('/parent/viewSecondParent', 'View\ParentController::viewSecondParent');
$routes->post('/parent/saveSecondParent', 'View\ParentController::saveSecondParent');

$routes->get('/parent/enroll_classes', 'View\ParentController::enrollClasses');
$routes->post('/parent/enroll_classes_handler', 'View\ParentController::enrollClassesHandler');
$routes->get('/parent/enroll_success', 'View\ParentController::enrollSuccess');
$routes->get('/parent/enroll_failure', 'View\ParentController::enrollFailure');
$routes->get('/parent/payment', 'View\ParentController::viewPayments');
$routes->get('/parent/calendar', 'View\SchoolCalendarController::calendarParentView');
$routes->get('/parent/attendance', 'View\ParentController::attendance');
// Parent reporting: absence/late/early dismissal
$routes->get('parent/report-attendance', 'View\ParentAttendanceReportController::form');
$routes->post('parent/report-attendance', 'View\ParentAttendanceReportController::submit');
$routes->post('parent/report-attendance/update', 'View\ParentAttendanceReportController::update');
$routes->get('attendance/parent-reports', 'View\ParentAttendanceReportController::list');
// Admin/Teacher: early dismissal page by month
$routes->get('attendance/early-dismissals', 'View\ParentAttendanceReportController::earlyDismissals');
// Admin/Teacher: add early dismissal
$routes->get('attendance/early-dismissals/new', 'View\ParentAttendanceReportController::addEarlyDismissalForm');
$routes->post('attendance/early-dismissals', 'View\ParentAttendanceReportController::saveEarlyDismissal');
$routes->post('attendance/early-dismissals/signature', 'View\ParentAttendanceReportController::uploadEarlyDismissalSignature');
// Parent report: client-side check API
$routes->post('api/parent/report-attendance/check', 'View\ParentAttendanceReportController::checkExisting');


$routes->get('/support', 'View\StatsController::support');

$routes->get('no-kids', 'View\ParentController::noKids');
$routes->match(['get', 'post'], 'parent/edit-student/(:num)', 'View\ParentController::editStudent/$1');
$routes->get('parent/edit-all-students', 'View\ParentController::showEditAllStudentsModal');
$routes->post('parent/edit-all-students', 'View\ParentController::updateAllStudents');

// Show registration form with dynamic student and emergency contact blocks
$routes->get('/parent/register_student', 'View\ParentController::registerStudentForm');
$routes->get('/parent/child_register', 'View\ParentController::registerKidCheck');

// Handle form submission (students + emergency contacts)
$routes->post('/parent/register_student/save', 'View\ParentController::saveStudentRegistration');
$routes->post('/parent/update_student/(:num)', 'View\ParentController::updateStudent/$1');
$routes->get('/parent/edit_student/(:num)', 'View\ParentController::editStudent/$1');
$routes->post('/parent/edit_student/(:num)', 'View\ParentController::editStudent/$1');
$routes->post('/parent/delete_student/(:num)', 'View\ParentController::deleteStudent/$1');

$routes->get('/parent/edit_emergency_contact/(:num)', 'View\ParentController::editEmergencyContact/$1');
$routes->post('/parent/edit_emergency_contact/(:num)', 'View\ParentController::editEmergencyContact/$1');


/*management navigation bar*/
$routes->get('nav-builder',               'View\NavBuilderController::index',   ['filter' => 'auth']);
$routes->get('api/nav-builder',           'View\NavBuilderController::data',    ['filter' => 'auth']);
$routes->post('nav-builder/save',         'View\NavBuilderController::save',    ['filter' => 'auth']);
$routes->get('nav-builder/delete/(:num)', 'View\NavBuilderController::delete/$1', ['filter' => 'auth']);
$routes->post('nav-builder/reorder',      'View\NavBuilderController::reorder', ['filter' => 'auth']);


// Inventory routes
$routes->group('inventory', ['filter' => 'csrf'], static function ($routes) {

    /** ---------------------------
     *  Movements (put FIRST)
     *  --------------------------- */
    $routes->group('movements', static function ($routes) {
        $routes->get('/',              'View\InventoryController::movementsIndex');       // /inventory/movements
        $routes->get('create',         'View\InventoryController::movementsCreate');      // /inventory/movements/create
        $routes->post('store',         'View\InventoryController::movementsStore');       // /inventory/movements/store
        $routes->get('edit/(:num)',    'View\InventoryController::movementsEdit/$1');     // /inventory/movements/edit/123
        $routes->post('update/(:num)', 'View\InventoryController::movementsUpdate/$1');   // /inventory/movements/update/123
        $routes->post('delete/(:num)', 'View\InventoryController::movementsDelete/$1');   // /inventory/movements/delete/123
        $routes->post('bulk-delete',   'View\InventoryController::movementsBulkDelete');
    });

    /** ---------------------------
     *  Existing inventory features
     *  --------------------------- */
    // Summary & actions (keep these BEFORE the wildcard too)
    $routes->get('summary-all',                 'View\InventoryController::summaryAll');
    $routes->get('adjust/(:num)',               'View\InventoryController::adjustForm/$1');
    $routes->post('adjust/(:num)',              'View\InventoryController::adjustStore/$1');
    $routes->get('books/distribute',            'View\InventoryController::teacherDistributeForm');
    $routes->post('books/distribute',           'View\InventoryController::teacherDistributeStore');
    $routes->get('classroom/audit/(:num)',      'View\InventoryController::auditClassroomForm/$1');
    $routes->post('classroom/audit/(:num)',     'View\InventoryController::auditClassroomStore/$1');

    // CRUD for items/categories
    $routes->get('create/(:alpha)',             'View\InventoryController::create/$1');
    $routes->post('store',                      'View\InventoryController::store');
    $routes->get('edit/(:num)',                 'View\InventoryController::edit/$1');
    $routes->post('update/(:num)',              'View\InventoryController::update/$1');
    $routes->post('delete/(:num)',              'View\InventoryController::delete/$1');
    $routes->post('category/save',              'View\InventoryController::saveCategory');

    /** ---------------------------
     *  Index & section switcher
     *  --------------------------- */
    $routes->get('/',                           'View\InventoryController::index'); // default
    // Narrow the wildcard to ONLY the sections you expect:
    $routes->get('(classroom|book|office|kitchen)', 'View\InventoryController::index/$1');
    // If you truly need any alpha, leave this LAST (but prefer the narrowed one above)
    // $routes->get('(:alpha)', 'View\InventoryController::index/$1');
});




$routes->get('admin/enrollment/new-students', 'View\AdministratorController::showNewStudents', ['filter' => 'auth:view_new_students']);


//Emergency Contact
$routes->get('administrator/emergency_contact', 'View\EmergencyContactController::index');
$routes->get('administrator/emergency_contact/edit/(:num)', 'View\EmergencyContactController::edit/$1');
$routes->get('administrator/emergency_contact/delete/(:num)', 'View\EmergencyContactController::delete/$1');
$routes->match(['get', 'post'], 'administrator/emergency_contact/update/(:num)', 'View\EmergencyContactController::update/$1');
// API: Emergency contacts (admin)
$routes->get('api/admin/emergency-contacts', 'View\EmergencyContactController::data');


$routes->group('staff', function ($routes) {
    $routes->get('/', 'View\StaffController::index'); // this maps to /staff
    $routes->get('index', 'View\StaffController::index'); // this maps to /staff/index
    $routes->get('create', 'View\StaffController::create');
    $routes->post('store', 'View\StaffController::store');
    $routes->get('edit/(:num)', 'View\StaffController::edit/$1');
    $routes->post('update/(:num)', 'View\StaffController::update/$1');
});

//Communication routes
/*
$routes->group('communications', ['filter' => 'auth'], function($routes) {
    $routes->get('comm_index',    'View\CommunicationController::index',   ['filter' => 'permission:comm_index']);
    $routes->post('comm_preview', 'View\CommunicationController::preview', ['filter' => 'permission:comm_preview']);
    $routes->post('comm_send',    'View\CommunicationController::send',    ['filter' => 'permission:comm_send']);
});
*/

$routes->group('communications',  static function ($routes) {
    $routes->get('comm_index', 'View\CommunicationController::index');
    $routes->post('preview', 'View\CommunicationController::preview');
    $routes->post('send', 'View\CommunicationController::send');
});


// AJAX — Families & Guardians (use FamilyController JSON endpoints)
// Consolidated to FamilyController to avoid duplicate route definitions
// and remove AJAX-only check in View\CommunicationController
// API endpoints:
//   GET api/students/{id}/families
//   GET api/families/{id}/guardians
// These are defined below in the `api` group.

////////////////////////////////////////////////

// app/Config/Routes.php
$routes->group('api',  static function ($routes) {
    // Families & Guardians API
    $routes->get('students/(:num)/families', 'FamilyController::familiesByStudent/$1');
    $routes->get('families/(:num)/guardians', 'FamilyController::guardiansByFamily/$1');
});

$routes->group('families',  static function ($routes) {
    // Allow GET for convenience in browser; keep POST for API/automation
    $routes->match(['get', 'post'], 'bootstrap', 'FamilyController::bootstrap');   // protect with auth in production
    $routes->post('attach-second-by-user',  'FamilyController::attachSecondByUser');
    $routes->post('attach-second-by-email', 'FamilyController::attachSecondByEmail');

    $routes->post('set-primary-home',       'FamilyController::setPrimaryHome');
    $routes->post('set-guardian-flags',     'FamilyController::setGuardianFlags');
    $routes->post('unlink-guardian',        'FamilyController::unlinkGuardian');
    $routes->post('unlink-student',         'FamilyController::unlinkStudent');
});
// Allow GET for manual triggering from browser
$routes->match(['get', 'post'], 'families/import-legacy', 'FamilyController::importSecondParentsFromLegacy');

// Admin page (protect with your auth/permission)
$routes->group('family',  static function ($routes) {
    $routes->get('', 'View\FamilyAdminController::index');
    $routes->get('index', 'View\FamilyAdminController::index');
    $routes->get('search', 'View\FamilyAdminController::search');
    $routes->get('card', 'View\FamilyAdminController::card');
    $routes->get('compose-email', 'View\FamilyAdminController::composeEmail');
    $routes->post('compose-email/send', 'View\FamilyAdminController::sendComposeEmail');
});
// Convenience alias
$routes->get('family', 'View\FamilyAdminController::index');
//////////////////////////////////////////////////////////

//upload files
$routes->get('receipts/(:any)', 'View\FilesController::receipt/$1', ['filter' => 'auth']);
$routes->get('reimbreceipts/(:any)', 'View\FilesController::reimb/$1', ['filter' => 'auth']); // serves from writable/uploads/reimbursements
$routes->get('early-dismissal-signatures/(:any)', 'View\FilesController::earlyDismissalSignature/$1');
// Expenses
$routes->get('expenses/edit/(:num)',   'View\ExpenseController::edit/$1', ['filter' => 'auth:view_financial_reports|administrator|administrative staff|principal']);
$routes->post('expenses/update/(:num)', 'View\ExpenseController::update/$1', ['filter' => 'auth:view_financial_reports|administrator|administrative staff|principal,update']);

// Reimbursements
$routes->get('reimbursements/edit/(:num)',    'View\ReimbursementController::edit/$1', ['filter' => 'auth:view_financial_reports|administrator|administrative staff|principal']);
$routes->post('reimbursements/update/(:num)', 'View\ReimbursementController::update/$1', ['filter' => 'auth:view_financial_reports|administrator|administrative staff|principal,update']);



// app/Config/Routes.php
$routes->get('whatsapp/', 'View\WhatsappController::index');
$routes->post('whatsapp/sendInvites', 'View\WhatsappController::sendInvites');
$routes->post('whatsapp/saveLink', 'View\WhatsappController::saveLink');
$routes->get('whatsapp/parent-contacts', 'View\WhatsappController::parentContacts');
$routes->get('whatsapp/parent-contacts-by-class', 'View\WhatsappController::parentContactsByClass');
// Track WhatsApp group membership per class/parent
$routes->match(['get', 'post'], 'whatsapp/update-membership', 'View\WhatsappController::updateMembership');




//Attendance
$routes->get('admin/teacher-attendance',       'View\AttendanceController::index', ['filter' => 'auth:admin']);
$routes->post('admin/teacher-attendance/save',  'View\AttendanceController::save',  ['filter' => 'auth:admin']);
// NEW: monthly overview (all sections)
$routes->get('admin/teacher-attendance/month',      'View\AttendanceController::month',     ['filter' => 'auth:admin']);
$routes->get('admin/teacher-attendance/month.csv',  'View\AttendanceController::monthCsv',  ['filter' => 'auth:admin']);
$routes->get('api/admin/teacher-attendance/month',  'View\AttendanceController::monthData', ['filter' => 'auth:admin']);


$routes->post('attendance/record', 'View\AttendanceTrackingController::record');
$routes->get('attendance/view/(:num)', 'View\AttendanceTrackingController::viewStudentCase/$1');
$routes->get('attendance/violations', 'View\AttendanceTrackingController::pendingViolationsView');
$routes->get('attendance/parents-info', 'View\AttendanceTrackingController::parentsInfo');
// Admin/Teacher: view parent submissions

// app/Config/Routes.php
$routes->post('attendance/send-auto-emails', 'View\AttendanceTrackingController::sendAutoEmails');
$routes->get('attendance/compose', 'View\AttendanceTrackingController::compose');
$routes->post('attendance/send-email-manual', 'View\AttendanceTrackingController::sendEmailManual');
$routes->post('attendance/notify_parent', 'View\AttendanceTrackingController::notify_parent');
$routes->get('attendance/violations/notified', 'View\AttendanceTrackingController::notifiedViolationsView');
$routes->post('attendance/save-note', 'View\AttendanceTrackingController::saveNotificationNote');



//});
// app/Config/Routes.php
$routes->get('admin/admins-attendance', 'View\AttendanceController::admins');
$routes->post('admin/admins-attendance/save', 'View\AttendanceController::saveAdmins');


$routes->post('admin/teacher-attendance/save-cell', 'View\AttendanceController::saveCell');
$routes->post('admin/admins-attendance/save-cell',  'View\AttendanceController::saveCell');


$routes->get('parent/edit-emergency-contact', 'View\ParentController::editEmergencyContact');
$routes->match(['get', 'post'], 'parent/edit-emergency-contact/(:num)', 'View\ParentController::editEmergencyContact/$1');


$routes->get('rfid_coming_soon', 'View\RFIDController::rfidComingSoon');


$routes->post('/parent/save-emergency-contact', 'View\ParentController::saveEmergencyContact');
$routes->get('/parent/add-emergency-form', 'View\ParentController::addEmergencyForm');


$routes->get('report/combined', 'View\ScorePredictor::combinedReport');


//$routes->get('/parent/withdraw_success', 'View\ParentController::withdraw_success');

$routes->get('/profile/(:num)', 'View\ParentController::profile/$1');
$routes->post('/parent/updateProfile/(:num)', 'View\ParentController::updateProfile/$1');

$routes->get('/preferences/(:num)', 'View\PreferencesController::index/$1');
$routes->post('/preferences/update/(:num)', 'View\PreferencesController::updatePreferences/$1');

// Route to view_add_edit the configuration page
$routes->get('/configuration/configuration_view', 'View\ConfigurationController::index');
$routes->get('/api/configuration', 'View\ConfigurationController::listData');
$routes->post('/configuration/addConfig', 'View\ConfigurationController::addConfig');
$routes->match(['get', 'post'], '/configuration/editConfig/(:num)', 'View\ConfigurationController::editConfig/$1');
$routes->post('/configuration/deleteConfig/(:num)', 'View\ConfigurationController::deleteConfig/$1');

// School-year management
$routes->group('administrator/school-years', ['filter' => 'auth:admin'], static function ($routes) {
    $routes->get('', 'Administrator\SchoolYearController::index');
    $routes->post('store', 'Administrator\SchoolYearController::store');
    $routes->post('(:num)/update', 'Administrator\SchoolYearController::update/$1');
    $routes->post('(:num)/activate', 'Administrator\SchoolYearController::activate/$1');
    $routes->post('(:num)/delete-draft', 'Administrator\SchoolYearController::deleteDraft/$1');
    $routes->post('(:num)/archive', 'Administrator\SchoolYearController::archive/$1');
    $routes->post('(:num)/reopen', 'Administrator\SchoolYearController::reopen/$1');
    $routes->get('(:num)/closing/preview', 'Administrator\SchoolYearClosingController::preview/$1');
    $routes->post('(:num)/closing/start', 'Administrator\SchoolYearClosingController::start/$1');
    $routes->post('(:num)/closing/execute', 'Administrator\SchoolYearClosingController::execute/$1');
    $routes->post('(:num)/closing/complete', 'Administrator\SchoolYearClosingController::complete/$1');
    $routes->post('(:num)/closing/cancel', 'Administrator\SchoolYearClosingController::cancel/$1');
});

// Route for Attendance Comment Templates
$routes->get('/administrator/attendance-templates', 'View\AttendanceCommentTemplateController::index');
$routes->get('/api/attendance-templates', 'View\AttendanceCommentTemplateController::listData');
$routes->post('/api/attendance-templates/save', 'View\AttendanceCommentTemplateController::save');
$routes->post('/api/attendance-templates/delete', 'View\AttendanceCommentTemplateController::delete');

// Route for handling form submission (POST)
$routes->post('admin/enroll_withdrawal_handler', 'View\AdministratorController::adminEnrollmentWithdrawalHandler');

// Route for displaying the enrollment/withdrawal page (GET)
$routes->get('enroll_withdraw/enrollment_withdrawal', 'View\AdministratorController::showEnrollmentWithdrawalPage');
// API: Enrollment/Withdrawal data (admin)
$routes->get('api/admin/enrollment-withdrawal', 'View\AdministratorController::enrollmentWithdrawalData');

$routes->post('/administrator/userSearch', 'View\AdministratorController::userSearch');
$routes->get('/administrator/userSearch', 'View\AdministratorController::userSearch');


$routes->get('administrator/administratordashboard', 'View\AdministratorController::administratorDashboard'); //administrator dashboard
$routes->get('api/administrator/dashboard', 'View\AdministratorController::dashboardMetrics');

//send email call
$routes->get('send-email', 'View\EmailController::sendEmail');

$routes->get('/admin/dashboard', 'DashboardController::admin');
$routes->get('/student/dashboard', 'DashboardController::student');


// Define the route for class schedules
$routes->get('/administrator/student_class_assignment', 'View\StudentController::studentClassAssignment');
$routes->post('students/assign-class', 'View\StudentController::assignClassStudent');

// IP Ban management
$routes->get('administrator/ip_bans', 'View\IpBanController::index');
$routes->post('administrator/ip_bans/unban', 'View\IpBanController::unban');
$routes->match(['get', 'post'], 'administrator/ip_bans/ban-now', 'View\IpBanController::banNow');




//Route to display the settings page
$routes->get('/administrator/settings', 'View\SettingsController::index');
// Route to update settings
$routes->post('/administrator/settings/update', 'View\SettingsController::update');

// Define the route for class schedules
$routes->get('/administrator/class_assignment', 'View\AssignmentController::index');
// API: Classes list (admin)
$routes->get('api/admin/class-assignment', 'View\AssignmentController::classAssignmentData');
// app/Config/Routes.php
$routes->get('/dashboard', 'View\DashboardRedirectController::dashboard');

$routes->get('emails/parent_email_extractor', 'View\EmailExtractorController::index');
$routes->get('api/emails', 'View\EmailExtractorController::getEmails');
$routes->post('api/compare', 'View\EmailExtractorController::compare');


$routes->get('/policy/picture_policy', 'View\PolicyController::schoolPicturePolicy');
$routes->get('/policy/school_policy', 'View\PolicyController::schoolPolicy');

$routes->get('/privacy_policy', 'View\PageController::privacyPolicy');
$routes->get('/terms_of_service', 'View\PageController::termsOfService');
$routes->get('/help_center', 'View\PageController::helpCenter');

//payment
$routes->get('/payment', 'View\PaymentController::redirectPage', ['filter' => 'auth:parent']);
$routes->get('/payment/manual', 'View\PaymentController::manual');
$routes->post('/payment/manual', 'View\PaymentController::manual');

// Voucher management
$routes->get('discounts/list', 'View\DiscountController::listVouchers', ['filter' => 'auth:view_invoice|view_financial_reports|administrator|administrative staff|principal']);
$routes->match(['get', 'post'], 'discount/create', 'View\DiscountController::createVoucher', ['filter' => 'auth:create_invoice|view_financial_reports|administrator|administrative staff|principal,create']);
$routes->match(['get', 'post'], 'discount/editVoucher/(:num)', 'View\DiscountController::editVoucher/$1', ['filter' => 'auth:update_invoice|view_financial_reports|administrator|administrative staff|principal,update']);
$routes->match(['get', 'post'], 'discount/apply', 'View\DiscountController::applyVoucher', ['filter' => 'auth:update_invoice|view_financial_reports|administrator|administrative staff|principal,update']);




// app/Config/Routes.php
$routes->post('submit_contact_form', 'View\PageController::submitContactForm');

// app/Config/Routes.php
$routes->get('/logout', 'AuthController::logout');

$routes->get('/stats', 'Stats::index');

// Define the route for user registration
$routes->get('/register', 'View\RegisterController::index');
$routes->post('/register', 'View\RegisterController::register');
$routes->get('/register/success', 'View\RegisterController::success');


$routes->get('/parent/add-student-form', 'View\ParentController::addStudentForm');


$routes->get('/landing_page/admin_dashboard', 'View\LandingPageController::admin', ['filter' => 'auth:admin_dashboard,read']);
$routes->get('/teacher_dashboard', 'View\LandingPageController::teacher', ['filter' => 'auth:teacher_dashboard,read']);
$routes->get('/landing_page/student_dashboard', 'View\LandingPageController::student', ['filter' => 'auth:student_dashboard,read']);
$routes->get('/parent_dashboard', 'View\LandingPageController::parentDashboard', ['filter' => 'auth:parent_dashboard,read']);
$routes->get('/landing_page/guest_dashboard', 'View\LandingPageController::guest', ['filter' => 'auth:guest_dashboard,read']);
$routes->get('/dashboard', 'View\LandingPageController::index');
$routes->get('/access_denied', 'ErrorController::accessDenied');


$routes->post('administrator/students/update', 'View\StudentController::editStudentData', ['filter' => 'auth:edit_student,update']);
$routes->post('administrator/students/set-active', 'View\StudentController::setStudentActive', ['filter' => 'auth:edit_student,update']);

/*
 * --------------------------------------------------------------------
 * routes for View\SupportController
 * --------------------------------------------------------------------
 */

$routes->get('/support', 'View\SupportController::index');
$routes->post('support/submit', 'View\SupportController::submit');
$routes->get('/support/requests', 'View\SupportController::requests');

//test roue:
$routes->get('test', function () {
    return 'Route is working!';
});

$routes->get('cleanup/unverified-users', 'CleanupController::cleanupUnverifiedUsers');
$routes->get('/refresh_teacher_assignments', 'View\TeacherController::refreshTeacherAssignments');

// Log Scans
$routes->post('rfid/process', 'View\RFIDController::process');
$routes->get('rfid/log', 'View\RFIDController::log');

$routes->get('flags/flags_management', 'View\FlagController::index');
$routes->get('flags/processed_flags', 'View\FlagController::processedFlags');
$routes->get('flags/incident_analysis', 'View\FlagController::incidentAnalysis');
$routes->post('flags/add', 'View\FlagController::addFlag');
$routes->get('/flags/update_state/(:num)', 'View\FlagController::updateState/$1');
$routes->post('/flags/update_state/(:num)', 'View\FlagController::updateState/$1');
$routes->get('flags/getStudentsByGrade/(:num)', 'View\FlagController::getStudentsByGrade/$1');
$routes->get('flags/history', 'View\FlagController::history');
$routes->post('flags/closeFlag/(:num)', 'View\FlagController::closeFlag/$1');
$routes->post('flags/cancelFlag/(:num)', 'View\FlagController::cancelFlag/$1');




// Permission management inside View\RolePermissionController


// Add a new permission (requires create_permission right)
$routes->match(
    ['get', 'post'],
    'rolepermission/add_permission',
    'View\RolePermissionController::addPermission',
    ['filter' => 'auth:create_permission']
);

// Edit an existing permission (requires edit_permission right)
$routes->match(
    ['get', 'post'],
    'rolepermission/edit_permission/(:num)',
    'View\RolePermissionController::editPermission/$1',
    ['filter' => 'auth:edit_permission']
);

// Delete a permission (requires delete_permission right)
$routes->post(
    'rolepermission/delete_permission/(:num)',
    'View\RolePermissionController::deletePermission/$1',
    ['filter' => 'auth:delete_permission']
);

// List all permissions
$routes->get(
    'rolepermission/list_permissions',
    'View\RolePermissionController::listPermissions',
    ['filter' => 'auth:read_permission']
);


/*
 * --------------------------------------------------------------------
 * Mobile API Routes (JWT Authentication)
 * --------------------------------------------------------------------
 * All API routes for mobile app access
 * Protected with JWT token authentication via ApiAuthFilter
 */
$routes->group('api/v1', ['filter' => 'apiAuth', 'namespace' => 'App\Controllers\Api'], function ($routes) {
    // Students
    $routes->get('students', 'View\UserController::index');
    $routes->get('students/(:num)', 'View\SupportController::show/$1');
    $routes->post('students', 'View\TeacherController::create');
    $routes->put('students/(:num)', 'View\TeacherController::update/$1');

    // Parents
    $routes->get('parents', 'View\UserController::index');
    $routes->get('parents/(:num)', 'View\SupportController::show/$1');
    $routes->get('parents/(:num)/students', 'View\SupportController::getStudents/$1');

    // Classes
    $routes->get('classes', 'View\UserController::index');
    $routes->get('classes/(:num)', 'View\SupportController::show/$1');
    $routes->get('classes/(:num)/students', 'View\SupportController::getStudents/$1');

    // Attendance
    $routes->get('attendance', 'View\UserController::index');
    $routes->get('attendance/student/(:num)', 'View\SupportController::getByStudent/$1');
    $routes->post('attendance', 'View\TeacherController::create');
    $routes->put('attendance/(:num)', 'View\TeacherController::update/$1');

    // Scores/Grades
    $routes->get('scores', 'View\UserController::index');
    $routes->get('scores/student/(:num)', 'View\SupportController::getByStudent/$1');
    $routes->post('scores', 'View\TeacherController::create');
    $routes->put('scores/(:num)', 'View\TeacherController::update/$1');

    // Payments
    $routes->get('payments', 'View\UserController::index');
    $routes->get('payments/(:num)', 'View\SupportController::show/$1');
    $routes->get('payments/parent/(:num)', 'View\SupportController::getByParent/$1');
    $routes->post('payments', 'View\TeacherController::create');
    $routes->put('payments/(:num)', 'View\TeacherController::update/$1');

    // Invoices
    $routes->get('invoices', 'View\UserController::index');
    $routes->get('invoices/(:num)', 'View\SupportController::show/$1');
    $routes->get('invoices/parent/(:num)', 'View\SupportController::getByParent/$1');
    $routes->put('invoices/(:num)', 'View\TeacherController::update/$1');

    // Notifications
    $routes->get('notifications', 'View\UserController::index');
    $routes->get('notifications/(:num)', 'View\SupportController::show/$1');
    $routes->post('notifications/(:num)/read', 'View\SupportController::markRead/$1');

    // Events/Calendar
    $routes->get('events', 'View\UserController::index');
    $routes->get('events/(:num)', 'View\SupportController::show/$1');

    // Calendar/School Calendar
    $routes->get('calendar', 'CalendarController::index');
    $routes->get('calendar/(:num)', 'CalendarController::show/$1');
    $routes->post('calendar', 'CalendarController::create');
    $routes->put('calendar/(:num)', 'CalendarController::update/$1');
    $routes->delete('calendar/(:num)', 'CalendarController::delete/$1');

    // Expenses
    $routes->get('expenses', 'View\UserController::index');
    $routes->get('expenses/(:num)', 'View\SupportController::show/$1');
    $routes->post('expenses', 'View\TeacherController::create');
    $routes->put('expenses/(:num)', 'View\TeacherController::update/$1');

    // Reimbursements
    $routes->get('reimbursements', 'View\UserController::index');
    $routes->get('reimbursements/(:num)', 'View\SupportController::show/$1');
    $routes->post('reimbursements', 'View\TeacherController::create');
    $routes->put('reimbursements/(:num)', 'View\TeacherController::update/$1');

    // Dashboard Data
    $routes->get('dashboard', 'DashboardController::index');
    $routes->get('dashboard/stats', 'DashboardController::stats');

    // Messages
    $routes->get('messages', 'View\UserController::index');
    $routes->get('messages/(:num)', 'View\SupportController::show/$1');
    $routes->post('messages', 'View\SupportController::send');

    // Homework
    $routes->get('homework', 'View\UserController::index');
    $routes->get('homework/student/(:num)', 'View\SupportController::getByStudent/$1');
    $routes->post('homework', 'View\TeacherController::create');
    $routes->put('homework/(:num)', 'View\TeacherController::update/$1');

    // Students - add delete route
    $routes->delete('students/(:num)', 'View\TeacherController::delete/$1');

    // Assignments
    $routes->get('assignments', 'View\UserController::index');
    $routes->get('assignments/(:num)', 'View\SupportController::show/$1');

    // Teachers
    $routes->get('teachers', 'View\UserController::index');
    $routes->get('teachers/(:num)', 'View\SupportController::show/$1');
    $routes->get('teachers/(:num)/classes', 'View\SupportController::getClasses/$1');

    // Quizzes
    $routes->get('quizzes', 'View\UserController::index');
    $routes->get('quizzes/(:num)', 'View\SupportController::show/$1');
    $routes->get('quizzes/student/(:num)', 'View\SupportController::getByStudent/$1');
    $routes->post('quizzes', 'View\TeacherController::create');
    $routes->put('quizzes/(:num)', 'View\TeacherController::update/$1');

    // Projects
    $routes->get('projects', 'View\UserController::index');
    $routes->get('projects/(:num)', 'View\SupportController::show/$1');
    $routes->get('projects/student/(:num)', 'View\SupportController::getByStudent/$1');
    $routes->post('projects', 'View\TeacherController::create');
    $routes->put('projects/(:num)', 'View\TeacherController::update/$1');

    // Midterm Exams
    $routes->get('midterms/student/(:num)', 'View\SupportController::getByStudent/$1');
    $routes->post('midterms', 'View\TeacherController::create');
    $routes->put('midterms/(:num)', 'View\TeacherController::update/$1');

    // Final Exams
    $routes->get('finals/student/(:num)', 'View\SupportController::getByStudent/$1');
    $routes->post('finals', 'View\TeacherController::create');
    $routes->put('finals/(:num)', 'View\TeacherController::update/$1');

    // Participation
    $routes->get('participations/student/(:num)', 'View\SupportController::getByStudent/$1');
    $routes->post('participations', 'View\TeacherController::create');
    $routes->put('participations/(:num)', 'View\TeacherController::update/$1');

    // Settings
    $routes->get('settings/preferences', 'View\SupportController::preferences');
    $routes->put('settings/preferences', 'View\TeacherController::updatePreferences');
    $routes->get('settings/system', 'View\SupportController::system');

    // Refunds
    $routes->get('refunds', 'View\UserController::index');
    $routes->get('refunds/(:num)', 'View\SupportController::show/$1');
    $routes->post('refunds', 'View\TeacherController::create');
    $routes->put('refunds/(:num)', 'View\TeacherController::update/$1');

    // Discounts
    $routes->get('discounts', 'View\UserController::index');
    $routes->get('discounts/code/(:segment)', 'View\SupportController::getByCode/$1');
    $routes->post('discounts/apply', 'View\SupportController::apply');

    // Payment Transactions
    $routes->get('payment-transactions', 'View\UserController::index');
    $routes->get('payment-transactions/(:num)', 'View\SupportController::show/$1');
    $routes->get('payment-transactions/payment/(:num)', 'View\SupportController::getByPayment/$1');
    $routes->post('payment-transactions', 'View\TeacherController::create');

    // Emergency Contacts
    $routes->get('emergency-contacts', 'View\UserController::index');
    $routes->get('emergency-contacts/(:num)', 'View\SupportController::show/$1');
    $routes->get('emergency-contacts/parent/(:num)', 'View\SupportController::getByParent/$1');
    $routes->post('emergency-contacts', 'View\TeacherController::create');
    $routes->put('emergency-contacts/(:num)', 'View\TeacherController::update/$1');
    $routes->delete('emergency-contacts/(:num)', 'View\TeacherController::delete/$1');

    // Families
    $routes->get('families', 'View\UserController::index');
    $routes->get('families/(:num)', 'View\SupportController::show/$1');
    $routes->get('families/student/(:num)', 'View\SupportController::getByStudent/$1');
    $routes->get('families/(:num)/guardians', 'View\SupportController::getGuardians/$1');

    // Administrator
    $routes->get('administrator/dashboard', 'View\SupportController::dashboard');
    $routes->get('administrator/search', 'View\SupportController::search');
    $routes->get('administrator/enrollment-withdrawal', 'View\SupportController::enrollmentWithdrawal');

    // Staff
    $routes->get('staff', 'View\UserController::index');
    $routes->get('staff/(:num)', 'View\SupportController::show/$1');
    $routes->post('staff', 'View\TeacherController::create');
    $routes->put('staff/(:num)', 'View\TeacherController::update/$1');
    $routes->delete('staff/(:num)', 'View\TeacherController::delete/$1');

    // Financial
    $routes->get('financial/report', 'View\SupportController::report');
    $routes->get('financial/unpaid-parents', 'View\SupportController::unpaidParents');

    // Configuration
    $routes->get('configurations', 'View\UserController::index');
    $routes->get('configurations/(:num)', 'View\SupportController::show/$1');
    $routes->get('configurations/key/(:segment)', 'View\SupportController::getByKey/$1');
    $routes->post('configurations', 'View\TeacherController::create');
    $routes->put('configurations/(:num)', 'View\TeacherController::update/$1');
    $routes->delete('configurations/(:num)', 'View\TeacherController::delete/$1');

    // Contact
    $routes->post('contact', 'View\SupportController::submit');

    // Extra Charges
    $routes->get('extra-charges', 'View\UserController::index');
    $routes->get('extra-charges/(:num)', 'View\SupportController::show/$1');
    $routes->post('extra-charges', 'View\TeacherController::create');
    $routes->put('extra-charges/(:num)', 'View\TeacherController::update/$1');
    $routes->post('extra-charges/(:num)/void', 'View\SupportController::void/$1');
    $routes->get('extra-charges/parents', 'View\SupportController::parentOptions');

    // Flags
    $routes->get('flags', 'View\UserController::index');
    $routes->get('flags/(:num)', 'View\SupportController::show/$1');
    $routes->post('flags', 'View\TeacherController::create');
    $routes->put('flags/(:num)/state', 'View\TeacherController::updateState/$1');
    $routes->post('flags/(:num)/close', 'View\SupportController::close/$1');
    $routes->post('flags/(:num)/cancel', 'View\SupportController::cancel/$1');
    $routes->get('flags/students/by-grade/(:num)', 'View\SupportController::getStudentsByGrade/$1');

    // IP Bans
    $routes->get('ip-bans', 'View\UserController::index');
    $routes->get('ip-bans/(:num)', 'View\SupportController::show/$1');
    $routes->post('ip-bans/unban', 'View\SupportController::unban');
    $routes->post('ip-bans/ban', 'View\SupportController::ban');

    // Support
    $routes->post('support', 'View\SupportController::submit');
    $routes->get('support/requests', 'View\SupportController::requests');
    $routes->get('support/requests/(:num)', 'View\SupportController::show/$1');

    // Attendance Tracking
    $routes->post('attendance-tracking/record', 'View\SupportController::record');
    $routes->get('attendance-tracking/violations', 'View\SupportController::violations');
    $routes->get('attendance-tracking/student/(:num)', 'View\SupportController::getByStudent/$1');

    // Communication
    $routes->get('communication/students/(:num)/families', 'View\SupportController::getFamiliesByStudent/$1');
    $routes->get('communication/families/(:num)/guardians', 'View\SupportController::getGuardiansByFamily/$1');
    $routes->post('communication/preview', 'View\SupportController::preview');
    $routes->post('communication/send', 'View\SupportController::send');

    // Class Preparation
    $routes->get('class-preparation', 'View\UserController::index');
    $routes->get('class-preparation/(:num)', 'View\SupportController::show/$1');
    $routes->post('class-preparation/(:num)/mark-printed', 'View\SupportController::markPrinted/$1');

    // Stats
    $routes->get('stats', 'View\UserController::index');

    // Suppliers
    $routes->get('suppliers', 'View\UserController::index');
    $routes->get('suppliers/(:num)', 'View\SupportController::show/$1');
    $routes->post('suppliers', 'View\TeacherController::create');
    $routes->put('suppliers/(:num)', 'View\TeacherController::update/$1');
    $routes->delete('suppliers/(:num)', 'View\TeacherController::delete/$1');

    // Payment Notifications
    $routes->get('payment-notifications', 'View\UserController::index');
    $routes->post('payment-notifications/send', 'View\SupportController::send');

    // RFID
    $routes->post('rfid/process', 'View\SupportController::process');
    $routes->get('rfid/logs', 'View\SupportController::logs');

    // Nav Builder
    $routes->get('nav-builder', 'View\UserController::index');
    $routes->get('nav-builder/(:num)', 'View\SupportController::show/$1');
    $routes->post('nav-builder', 'View\TeacherController::create');
    $routes->put('nav-builder/(:num)', 'View\TeacherController::update/$1');
    $routes->delete('nav-builder/(:num)', 'View\TeacherController::delete/$1');
    $routes->post('nav-builder/reorder', 'View\SupportController::reorder');

    // Inventory
    $routes->get('inventory', 'View\UserController::index');
    $routes->get('inventory/(:num)', 'View\SupportController::show/$1');
    $routes->post('inventory', 'View\TeacherController::create');
    $routes->put('inventory/(:num)', 'View\TeacherController::update/$1');
    $routes->delete('inventory/(:num)', 'View\TeacherController::delete/$1');
    $routes->get('inventory/movements', 'View\SupportController::movements');

    // Preferences
    $routes->get('preferences', 'View\UserController::index');
    $routes->put('preferences', 'View\TeacherController::update');

    // Late Slip Logs
    $routes->get('late-slip-logs', 'View\UserController::index');
    $routes->get('late-slip-logs/(:num)', 'View\SupportController::show/$1');

    // Supply Categories
    $routes->get('supply-categories', 'View\UserController::index');
    $routes->get('supply-categories/(:num)', 'View\SupportController::show/$1');
    $routes->post('supply-categories', 'View\TeacherController::create');
    $routes->put('supply-categories/(:num)', 'View\TeacherController::update/$1');
    $routes->delete('supply-categories/(:num)', 'View\TeacherController::delete/$1');

    // Homework Tracking
    $routes->get('homework-tracking', 'View\UserController::index');

    // Parent Attendance Reports
    $routes->get('parent-attendance-reports', 'View\UserController::index');
    $routes->post('parent-attendance-reports', 'View\SupportController::submit');
    $routes->put('parent-attendance-reports/(:num)', 'View\TeacherController::update/$1');

    // Printables Reports
    $routes->get('printables/report-card/meta', 'View\ReportCardsController::reportCardMeta');
    $routes->get('printables/report-card/completeness', 'View\ReportCardsController::reportCardCompleteness');
    $routes->get('printables/badges/status', 'View\BadgesController::badgePrintStatus');
    $routes->post('printables/badges/log', 'View\BadgesController::logBadgePrint');

    // Broadcast Email
    $routes->post('broadcast-email/send', 'View\SupportController::send');
    $routes->get('broadcast-email/parents', 'View\SupportController::parents');

    // Role Permissions
    $routes->get('roles', 'View\SupportController::roles');
    $routes->get('roles/(:num)', 'View\SupportController::showRole/$1');
    $routes->get('roles/(:num)/permissions', 'View\SupportController::rolePermissions/$1');
    $routes->get('permissions', 'View\SupportController::permissions');
    $routes->post('users/(:num)/roles', 'View\RolePermissionController::assignRole/$1');
    $routes->get('users/role-assignment', 'View\SupportController::users');

    // WhatsApp
    $routes->get('whatsapp/links', 'View\SupportController::links');
    $routes->post('whatsapp/links', 'View\SupportController::saveLink');
    $routes->put('whatsapp/membership', 'View\TeacherController::updateMembership');

    // Purchase Orders
    $routes->get('purchase-orders', 'View\UserController::index');
    $routes->get('purchase-orders/(:num)', 'View\SupportController::show/$1');
    $routes->post('purchase-orders', 'View\TeacherController::create');
    $routes->put('purchase-orders/(:num)', 'View\TeacherController::update/$1');

    // Grading
    $routes->get('grading/(:segment)/(:num)/(:num)', 'View\SupportController::show/$1/$2/$3');
    $routes->put('grading', 'View\TeacherController::update');

    // Score Comments
    $routes->post('score-comments', 'View\SupportController::save');
    $routes->get('score-comments/student/(:num)', 'View\SupportController::getByStudent/$1');
    $routes->put('score-comments/(:num)', 'View\TeacherController::update/$1');

    // Authorized Users
    $routes->get('authorized-users', 'View\UserController::index');
    $routes->get('authorized-users/(:num)', 'View\SupportController::show/$1');
    $routes->post('authorized-users', 'View\TeacherController::create');
    $routes->delete('authorized-users/(:num)', 'View\TeacherController::delete/$1');

    // Email Extractor
    $routes->get('email-extractor/emails', 'View\SupportController::getEmails');
    $routes->post('email-extractor/compare', 'View\SupportController::compare');

    // Slip Printer
    $routes->post('slip-printer/print', 'View\SupportController::print');
    $routes->post('slip-printer/preview', 'View\SupportController::preview');

    // Score Predictor
    $routes->get('score-predictor/report', 'ScorePredictorController::report');

    // Family Admin
    $routes->get('family-admin', 'View\UserController::index');
    $routes->get('family-admin/search', 'View\SupportController::search');

    // School Calendar
    $routes->get('school-calendar', 'View\UserController::index');
    $routes->get('school-calendar/view/(:segment)', 'View\SupportController::view/$1');

    // Email
    $routes->post('email/send', 'View\SupportController::send');

    // Session Management
    $routes->get('session/timeout-config', 'SessionController::getTimeoutConfig');
    $routes->get('session/check', 'SessionController::checkTimeout');
    $routes->post('session/ping', 'SessionController::pingActivity');

    // Role Switcher
    $routes->get('role-switcher/roles', 'View\SupportController::getRoles');
    $routes->post('role-switcher/switch', 'View\SupportController::switchRole');

    // Files
    $routes->get('files', 'View\UserController::index');
    $routes->get('files/receipt/(:segment)', 'View\SupportController::receipt/$1');
    $routes->get('files/reimbursement/(:segment)', 'View\SupportController::reimbursement/$1');

    // Page
    $routes->post('page/contact', 'View\SupportController::submitContact');
    $routes->get('page/privacy-policy', 'View\SupportController::privacyPolicy');
    $routes->get('page/terms-of-service', 'View\SupportController::termsOfService');
    $routes->get('page/help-center', 'View\PageController::helpCenter');

    // SMS
    $routes->post('sms/send', 'View\SupportController::send');
    $routes->get('sms/carriers', 'View\SupportController::carriers');

    // Dashboard Redirect
    $routes->get('dashboard/route', 'View\SupportController::getRoute');

    // Landing Page
    $routes->get('landing-page/data', 'View\SupportController::getData');

    // Frontend
    $routes->get('frontend/user', 'View\SupportController::getUser');
    $routes->get('frontend/pages', 'View\SupportController::getPages');

    // UI
    $routes->get('ui/style', 'View\SupportController::getStyle');
    $routes->post('ui/style', 'View\TeacherController::updateStyle');

    // Info Icon
    $routes->get('info-icon/profile', 'View\SupportController::profileIcon');

    // Messaging
    $routes->get('messaging/conversations', 'MessagingController::conversations');
    $routes->get('messaging/conversation/(:num)', 'MessagingController::conversation/$1');
    $routes->post('messaging/send', 'MessagingController::send');
    $routes->post('messaging/mark-read', 'MessagingController::markRead');
    $routes->get('messaging/unread-count', 'MessagingController::unreadCount');
    $routes->get('messaging/search-users', 'MessagingController::searchUsers');
    $routes->delete('messaging/message/(:num)', 'MessagingController::deleteMessage/$1');
    $routes->delete('messaging/conversation/(:num)', 'MessagingController::deleteConversation/$1');
});

// API providers for users, parents, teachers, and related lookups
$routes->group('api/v1', ['namespace' => 'App\Controllers\Api', 'filter' => 'apiAuth'], function ($routes) {
    $routes->get('profile', 'UserController::profile');
    $routes->put('profile', 'UserController::updateProfile');
    $routes->get('users', 'RolePermissionController::users');
    $routes->get('admins', 'RolePermissionController::admins');
    $routes->get('parents', 'ParentController::index');
    $routes->get('teachers', 'TeacherController::index');
    $routes->get('classes', 'ClassController::index');
    $routes->get('emergency-contacts', 'EmergencyContactController::index');
    $routes->get('emergency-contacts/(:num)', 'EmergencyContactController::show/$1');
    $routes->get('emergency-contacts/parent/(:num)', 'EmergencyContactController::getByParent/$1');
});

// Public API routes (no auth required)
$routes->group('api/v1', ['namespace' => 'App\Controllers'], function ($routes) {
    $routes->post('login', 'AuthController::apiLogin');
    // Time routes use Api namespace
    $routes->get('time/now', 'Api\TimeController::now');
    $routes->post('time/convert', 'Api\TimeController::convert');
    // Health check (public)
    $routes->get('health', 'Api\HealthController::index');
    // Registration (public)
    $routes->post('register', 'Api\RegisterController::register');
    $routes->post('profile', 'Api\UserController::profileAuth');
});
/*
 * --------------------------------------------------------------------
 * Additional Routing
 * --------------------------------------------------------------------
 *
 * There will often be times that you need additional routing and you
 * need to it be able to override any defaults in this file. Environment
 * based routes is one such time. require() additional route files here
 * to make that happen.
 *
 * You will have access to the $routes object within that file without
 * needing to reload it.
 */
if (file_exists(APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php')) {
    require APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php';
}
// ---- Administrator API endpoints (added by Codex) ----
$routes->group('api/administrator', ['namespace' => 'App\\Controllers\\Api'], static function ($routes) {
    $routes->get('dashboard', 'AdministratorController::dashboard');
    $routes->get('absence', 'AdministratorController::absenceInfo', ['filter' => 'auth:admin']);
    $routes->post('absence', 'AdministratorController::submitAbsence', ['filter' => 'auth:admin']);
    $routes->get('search', 'AdministratorController::search', ['filter' => 'auth:admin']);
    $routes->get('enrollment-withdrawal/data', 'AdministratorController::enrollmentWithdrawalData', ['filter' => 'auth:admin']);
    $routes->post('enrollment-withdrawal/update', 'AdministratorController::updateEnrollmentStatuses', ['filter' => 'auth:admin']);
    $routes->get('students', 'AdministratorController::studentProfiles', ['filter' => 'auth:admin']);
    $routes->get('parents', 'AdministratorController::parentProfiles', ['filter' => 'auth:admin']);
});
// ---- Parent API additions (parity with View) ----
$routes->group('api/parents', ['namespace' => 'App\\Controllers\\Api'], static function ($routes) {
    $routes->get('(:num)/enroll-classes', 'ParentController::enrollClassesData/$1', ['filter' => 'auth:parent']);
    $routes->post('(:num)/enroll-classes', 'ParentController::updateEnrollments/$1', ['filter' => 'auth:parent']);
    // Emergency contacts
    $routes->get('(:num)/emergency-contacts', 'ParentController::emergencyContacts/$1', ['filter' => 'auth:parent']);
    $routes->post('(:num)/emergency-contacts', 'ParentController::saveEmergencyContact/$1', ['filter' => 'auth:parent']);
    // Authorized/second parent users
    $routes->get('(:num)/authorized-users', 'ParentController::authorizedUsers/$1', ['filter' => 'auth:parent']);
    $routes->post('(:num)/authorized-users', 'ParentController::addAuthorizedUser/$1', ['filter' => 'auth:parent']);
    // Student CRUD
    $routes->post('(:num)/students', 'ParentController::createStudent/$1', ['filter' => 'auth:parent']);
    $routes->put('(:num)/students/(:num)', 'ParentController::updateStudent/$1/$2', ['filter' => 'auth:parent']);
    $routes->delete('(:num)/students/(:num)', 'ParentController::deleteStudent/$1/$2', ['filter' => 'auth:parent']);
});
// ---- Competition Winners ----
$routes->group('admin', ['filter' => 'auth'], static function ($routes) {
    $routes->get('competition-winners', 'Admin\\CompetitionWinnersController::index');
    $routes->get('competition-winners/create', 'Admin\\CompetitionWinnersController::create');
    $routes->post('competition-winners/store', 'Admin\\CompetitionWinnersController::store');
    $routes->get('competition-winners/(:num)/settings', 'Admin\\CompetitionWinnersController::settings/$1');
    $routes->post('competition-winners/(:num)/update', 'Admin\\CompetitionWinnersController::update/$1');
    $routes->get('competition-winners/(:num)', 'Admin\\CompetitionWinnersController::edit/$1');
    $routes->post('competition-winners/(:num)/scores', 'Admin\\CompetitionWinnersController::saveScores/$1');
    $routes->get('competition-winners/(:num)/preview', 'Admin\\CompetitionWinnersController::preview/$1');
    $routes->get('competition-winners/(:num)/winners', 'Admin\\CompetitionWinnersController::winners/$1');
    $routes->get('competition-winners/(:num)/recognition-pdf', 'Admin\\CompetitionWinnersController::recognitionPdf/$1');
    $routes->post('competition-winners/(:num)/publish', 'Admin\\CompetitionWinnersController::publish/$1');
    $routes->post('competition-winners/(:num)/export-quiz', 'Admin\\CompetitionWinnersController::exportCompetitionToQuiz/$1');
    $routes->post('competition-winners/(:num)/export-quiz/(:num)', 'Admin\\CompetitionWinnersController::exportCompetitionToQuiz/$1/$2');
    $routes->post('competition-winners/(:num)/lock', 'Admin\\CompetitionWinnersController::lock/$1');
    $routes->post('competition-winners/(:num)/unlock', 'Admin\\CompetitionWinnersController::unlock/$1');
});

$routes->get('competition-winners', 'Admin\\CompetitionWinnersController::index', ['filter' => 'auth']);

$routes->get('winners/competitions', 'WinnersController::competitionIndex');
$routes->get('winners/competitions/(:num)', 'WinnersController::competitionShow/$1');
// ---- Swagger UI route ----
$routes->get('docs/swagger', 'View\\DocsController::swagger');
