<?php
require __DIR__ . '/bootstrap.php';

$route = $_GET['r'] ?? 'home';

$routes = [
    'home' => [PageController::class, 'home'],
    'media/ebook-cover' => [MediaController::class, 'ebookCover'],
    'media/professional-material-cover' => [MediaController::class, 'professionalMaterialCover'],
    'media/training-cover' => [MediaController::class, 'trainingCover'],
    'receipt/view' => [PageController::class, 'paymentReceipt'],
    'receipt/image' => [PageController::class, 'paymentReceiptImage'],


    'beginner/register' => [BeginnerController::class, 'register'],
    'beginner/register/post' => [BeginnerController::class, 'doRegister'],
    'beginner/login' => [BeginnerController::class, 'login'],
    'beginner/login/post' => [BeginnerController::class, 'doLogin'],
    'beginner/logout' => [BeginnerController::class, 'logout'],
    'beginner/panel' => [BeginnerController::class, 'panel'],
    'beginner/request' => [BeginnerController::class, 'requestContent'],
    'beginner/proof' => [BeginnerController::class, 'uploadProof'],
    'beginner/download' => [BeginnerController::class, 'downloadContent'],

    'login' => [AuthController::class, 'login'],
    'login/post' => [AuthController::class, 'doLogin'],
    'register' => [AuthController::class, 'register'],
    'register/post' => [AuthController::class, 'doRegister'],
    'logout' => [AuthController::class, 'logout'],

    'dashboard' => [StudentController::class, 'dashboard'],
    'calendar' => [StudentController::class, 'calendar'],
    'theory' => [StudentController::class, 'theory'],
    'book' => [StudentController::class, 'book'],
    'cancel' => [StudentController::class, 'cancel'],
    'absence/notify' => [StudentController::class, 'notifyAbsence'],
    'ebooks' => [StudentController::class, 'ebooks'],
    'ebooks/download' => [StudentController::class, 'downloadEbook'],
    'rate/professional' => [StudentController::class, 'rateProfessional'],
    'lessons' => [StudentController::class, 'lessons'],
    'quick-links' => [StudentController::class, 'quickLinks'],
    'profile/photo' => [StudentController::class, 'updateProfilePhoto'],

    'portal/messages' => [PortalController::class, 'messages'],
    'portal/messages/direct' => [PortalController::class, 'direct'],
    'portal/contacts' => [PortalController::class, 'contacts'],
    'portal/contacts/save' => [PortalController::class, 'saveContact'],
    'portal/contacts/delete' => [PortalController::class, 'deleteContact'],
    'portal/messages/send' => [PortalController::class, 'sendMessage'],
    'portal/messages/audio-chunk' => [PortalController::class, 'uploadAudioChunk'],
    'portal/messages/audio-finalize' => [PortalController::class, 'finalizeAudioUpload'],
    'portal/messages/group' => [PortalController::class, 'group'],
    'portal/messages/group-send' => [PortalController::class, 'sendGroupMessage'],
    'portal/messages/group-file' => [PortalController::class, 'groupFile'],
    'portal/messages/file' => [PortalController::class, 'messageFile'],
    'portal/messages/delete' => [PortalController::class, 'deleteMessage'],
    'portal/videos' => [PortalController::class, 'videos'],
    'portal/video-stream' => [PortalController::class, 'streamVideo'],
    'portal/payments' => [PortalController::class, 'payments'],
    'portal/payments/proof-upload' => [PortalController::class, 'uploadPaymentProof'],
    'portal/payments/proof-file' => [PortalController::class, 'paymentProofFile'],

    'professional/login' => [ProfessionalController::class, 'login'],
    'professional/login/post' => [ProfessionalController::class, 'doLogin'],
    'professional/logout' => [ProfessionalController::class, 'logout'],
    'professional/panel' => [ProfessionalController::class, 'panel'],
    'professional/profile/photo' => [ProfessionalController::class, 'updateProfilePhoto'],
    'professional/appointments' => [ProfessionalController::class, 'appointments'],
    'professional/messages' => [ProfessionalController::class, 'messages'],
    'professional/contacts' => [ProfessionalController::class, 'contacts'],
    'professional/material-download' => [ProfessionalController::class, 'downloadMaterial'],
    'professional/contacts/save' => [ProfessionalController::class, 'saveContact'],
    'professional/contacts/delete' => [ProfessionalController::class, 'deleteContact'],
    'professional/messages/send' => [ProfessionalController::class, 'sendMessage'],
    'professional/messages/unlock' => [ProfessionalController::class, 'unlockMessage'],
    'professional/messages/delete' => [ProfessionalController::class, 'deleteMessage'],
    'professional/rate-student' => [ProfessionalController::class, 'rateStudent'],
    'professional/confirm-lesson' => [ProfessionalController::class, 'confirmLesson'],
    'professional/student-level' => [ProfessionalController::class, 'saveStudentLevel'],
    'professional/mark-student-absence' => [ProfessionalController::class, 'markStudentAbsence'],
    'professional/notify-absence' => [ProfessionalController::class, 'notifyProfessionalAbsence'],
    'professional/theory-groups' => [ProfessionalController::class, 'theoryGroups'],
    'professional/theory-groups/save' => [ProfessionalController::class, 'saveTheoryGroup'],
    'professional/theory-videos' => [ProfessionalController::class, 'theoryVideos'],
    'professional/theory-videos/save' => [ProfessionalController::class, 'saveTheoryVideo'],
    'professional/theory-videos/upload-chunk' => [ProfessionalController::class, 'uploadTheoryVideoChunk'],
    'professional/theory-videos/delete' => [ProfessionalController::class, 'deleteTheoryVideo'],
    'professional/chat-groups' => [ProfessionalController::class, 'chatGroups'],
    'professional/chat-groups/save' => [ProfessionalController::class, 'saveChatGroup'],
    'professional/chat-groups/send' => [ProfessionalController::class, 'sendChatGroupMessage'],

    'admin/dashboard' => [AdminController::class, 'dashboard'],
    'admin/announcements' => [AdminController::class, 'announcements'],
    'admin/announcements/save' => [AdminController::class, 'saveAnnouncement'],
    'admin/announcements/toggle' => [AdminController::class, 'toggleAnnouncement'],
    'admin/announcements/delete' => [AdminController::class, 'deleteAnnouncement'],
    'admin/video-lessons' => [AdminController::class, 'videoLessons'],
    'admin/video-lessons/save' => [AdminController::class, 'saveVideoLesson'],
    'admin/video-lessons/upload-chunk' => [AdminController::class, 'uploadVideoChunk'],
    'admin/video-lessons/toggle' => [AdminController::class, 'toggleVideoLesson'],
    'admin/video-lessons/delete' => [AdminController::class, 'deleteVideoLesson'],
    'admin/video-lessons/grant' => [AdminController::class, 'grantVideoLesson'],
    'admin/video-lessons/revoke' => [AdminController::class, 'revokeVideoLesson'],
    'admin/payment-center' => [AdminController::class, 'paymentCenter'],
    'admin/payment-center/receipt-manual' => [AdminController::class, 'createManualPaymentReceipt'],
    'admin/payment-center/bank-save' => [AdminController::class, 'savePaymentBank'],
    'admin/payment-center/bank-toggle' => [AdminController::class, 'togglePaymentBank'],
    'admin/payment-center/bank-delete' => [AdminController::class, 'deletePaymentBank'],
    'admin/payment-center/charge-save' => [AdminController::class, 'savePaymentCharge'],
    'admin/payment-center/charge-status' => [AdminController::class, 'updatePaymentChargeStatus'],
    'admin/payment-center/charge-delete' => [AdminController::class, 'deletePaymentCharge'],
    'admin/payment-center/proof-delete' => [AdminController::class, 'deletePaymentProof'],
    'admin/theory-groups' => [AdminController::class, 'theoryGroups'],
    'admin/theory-groups/save' => [AdminController::class, 'saveTheoryGroup'],
    'admin/theory-groups/toggle' => [AdminController::class, 'toggleTheoryGroup'],
    'admin/theory-groups/delete' => [AdminController::class, 'deleteTheoryGroup'],
    'admin/messages' => [AdminController::class, 'messages'],
    'admin/students' => [AdminController::class, 'students'],
    'admin/student-payments' => [AdminController::class, 'studentPayments'],
    'admin/student-payments/save' => [AdminController::class, 'saveStudentPayment'],
    'admin/student-payments/delete' => [AdminController::class, 'deleteStudentPayment'],
    'admin/students/save' => [AdminController::class, 'saveStudent'],
    'admin/students/approve' => [AdminController::class, 'approveStudent'],
    'admin/students/update' => [AdminController::class, 'updateStudent'],
    'admin/students/package' => [AdminController::class, 'saveStudentPackage'],
    'admin/students/notes' => [AdminController::class, 'saveStudentNotes'],
    'admin/students/finish' => [AdminController::class, 'finishStudent'],
    'admin/students/reactivate' => [AdminController::class, 'reactivateStudent'],
    'admin/students/delete-finished' => [AdminController::class, 'deleteFinishedStudent'],
    'admin/appointments' => [AdminController::class, 'appointments'],
    'admin/appointments/manual' => [AdminController::class, 'saveManualAppointment'],
    'admin/appointments/package' => [AdminController::class, 'saveAppointmentPackageQuick'],
    'admin/appointments/reschedule' => [AdminController::class, 'rescheduleAppointment'],
    'admin/appointments/day-off-save' => [AdminController::class, 'saveProfessionalDayOff'],
    'admin/appointments/day-off-delete' => [AdminController::class, 'deleteProfessionalDayOff'],
    'admin/appointments/professional-options' => [AdminController::class, 'professionalOptionsJson'],
    'admin/appointments/unlock' => [AdminController::class, 'unlockAppointment'],
    'admin/appointments/color' => [AdminController::class, 'updateAppointmentColor'],
    'admin/appointments/lesson' => [AdminController::class, 'updateAppointmentLesson'],
    'admin/appointments/reopen' => [AdminController::class, 'reopenCompletedLesson'],
    'admin/appointments/history-delete' => [AdminController::class, 'deleteHistoricalAppointment'],
    'admin/appointments/history-delete-all' => [AdminController::class, 'deleteHistoricalStudent'],
    'admin/ratings' => [AdminController::class, 'ratings'],
    'admin/ebooks' => [AdminController::class, 'ebooks'],
    'admin/ebooks/save' => [AdminController::class, 'saveEbook'],
    'admin/ebooks/cover' => [AdminController::class, 'updateEbookCover'],
    'admin/ebooks/toggle' => [AdminController::class, 'toggleEbook'],
    'admin/ebooks/delete' => [AdminController::class, 'deleteEbook'],
    'admin/ebooks/grant' => [AdminController::class, 'grantEbook'],
    'admin/ebooks/revoke' => [AdminController::class, 'revokeEbook'],
    'admin/professional-materials' => [AdminController::class, 'professionalMaterials'],
    'admin/professional-materials/save' => [AdminController::class, 'saveProfessionalMaterial'],
    'admin/professional-materials/cover' => [AdminController::class, 'updateProfessionalMaterialCover'],
    'admin/professional-materials/toggle' => [AdminController::class, 'toggleProfessionalMaterial'],
    'admin/professional-materials/delete' => [AdminController::class, 'deleteProfessionalMaterial'],
    'admin/links' => [AdminController::class, 'links'],
    'admin/links/save' => [AdminController::class, 'saveLink'],
    'admin/links/toggle' => [AdminController::class, 'toggleLink'],
    'admin/links/delete' => [AdminController::class, 'deleteLink'],
    'admin/contacts' => [AdminController::class, 'contacts'],
    'admin/contacts/save' => [AdminController::class, 'saveContact'],
    'admin/contacts/delete' => [AdminController::class, 'deleteContact'],
    'admin/theory' => [AdminController::class, 'theory'],
    'admin/theory/save' => [AdminController::class, 'saveTheory'],
    'admin/theory/delete' => [AdminController::class, 'deleteTheory'],
    'admin/holidays' => [AdminController::class, 'holidays'],
    'admin/holidays/save' => [AdminController::class, 'saveHoliday'],
    'admin/holidays/delete' => [AdminController::class, 'deleteHoliday'],
    'admin/availability' => [AdminController::class, 'availability'],
    'admin/availability/save' => [AdminController::class, 'saveAvailability'],
    'admin/availability/unlock' => [AdminController::class, 'unlockSlot'],
    'admin/availability/delete' => [AdminController::class, 'deleteSlot'],
    'admin/professionals' => [AdminController::class, 'professionals'],
    'admin/professionals/save' => [AdminController::class, 'saveProfessional'],
    'admin/professionals/notes' => [AdminController::class, 'saveProfessionalNotes'],
    'admin/professionals/delete' => [AdminController::class, 'deleteProfessional'],
    'admin/professionals/toggle' => [AdminController::class, 'toggleProfessional'],
    'admin/professionals/refresh-token' => [AdminController::class, 'refreshProfessionalToken'],
    'admin/beginner-training' => [AdminController::class, 'beginnerTraining'],
    'admin/beginner-training/content-save' => [AdminController::class, 'saveTrainingContent'],
    'admin/beginner-training/content-cover' => [AdminController::class, 'updateTrainingContentCover'],
    'admin/beginner-training/content-toggle' => [AdminController::class, 'toggleTrainingContent'],
    'admin/beginner-training/content-delete' => [AdminController::class, 'deleteTrainingContent'],
    'admin/beginner-training/charge' => [AdminController::class, 'saveTrainingCharge'],
    'admin/beginner-training/order-status' => [AdminController::class, 'updateTrainingOrder'],
    'admin/beginner-training/instructor-status' => [AdminController::class, 'updateBeginnerStatus'],
    'admin/beginner-training/instructor-delete' => [AdminController::class, 'deleteBeginnerInstructor'],
    'admin/beginner-training/proof' => [AdminController::class, 'viewTrainingProof'],
    'admin/settings' => [AdminController::class, 'settings'],
    'admin/settings/save' => [AdminController::class, 'saveSettings'],
    'admin/account' => [AdminController::class, 'account'],
    'admin/account/save' => [AdminController::class, 'saveAccount'],
    'admin/backups' => [AdminController::class, 'backups'],
    'admin/backups/create' => [AdminController::class, 'createBackup'],
    'admin/backups/database' => [AdminController::class, 'downloadDatabaseBackup'],
    'admin/backups/download' => [AdminController::class, 'downloadBackup'],
    'admin/backups/restore' => [AdminController::class, 'restoreBackup'],
    'admin/backups/restore-saved' => [AdminController::class, 'restoreSavedBackup'],
    'admin/backups/delete' => [AdminController::class, 'deleteBackup'],
];

if (!isset($routes[$route])) {
    http_response_code(404);
    exit('Rota nao encontrada.');
}

[$class, $method] = $routes[$route];
$controller = new $class();
$controller->$method();
