<?php

declare(strict_types=1);

/**
 * Branch Admin Routes — COMPLETE FILE
 *
 * All routes for the Branch Admin panel.
 * URL prefix: /branch/*
 */

use App\Core\Router;

/** @var Router $router */

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

$router->get('/branch/login', 'BranchAdmin\Controllers\BranchAuthController@loginForm');
$router->post('/branch/login', 'BranchAdmin\Controllers\BranchAuthController@login');
$router->post('/branch/logout', 'BranchAdmin\Controllers\BranchAuthController@logout');

// ─── Branch Registration (Public Form) ───────────────────────────────────────

$router->get('/branch/register', 'BranchAdmin\Controllers\BranchApplicationController@form');
$router->post('/branch/register', 'BranchAdmin\Controllers\BranchApplicationController@submit');

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

$router->get('/branch', 'BranchAdmin\Controllers\BranchDashboardController@index', ['branch_admin']);
$router->get('/branch/dashboard', 'BranchAdmin\Controllers\BranchDashboardController@index', ['branch_admin']);

// ─── Branch Profile ──────────────────────────────────────────────────────────

$router->get('/branch/profile', 'BranchAdmin\Controllers\BranchProfileController@index', ['branch_admin']);
$router->post('/branch/profile', 'BranchAdmin\Controllers\BranchProfileController@update', ['branch_admin']);

// ─── Students Management ─────────────────────────────────────────────────────

$router->get('/branch/students', 'BranchAdmin\Controllers\BranchStudentController@index', ['branch_admin']);
$router->get('/branch/students/create', 'BranchAdmin\Controllers\BranchStudentController@create', ['branch_admin']);
$router->post('/branch/students', 'BranchAdmin\Controllers\BranchStudentController@store', ['branch_admin']);
$router->get('/branch/students/{id}', 'BranchAdmin\Controllers\BranchStudentController@show', ['branch_admin']);
$router->get('/branch/students/{id}/edit', 'BranchAdmin\Controllers\BranchStudentController@edit', ['branch_admin']);
$router->post('/branch/students/{id}', 'BranchAdmin\Controllers\BranchStudentController@update', ['branch_admin']);
$router->post('/branch/students/{id}/delete', 'BranchAdmin\Controllers\BranchStudentController@delete', ['branch_admin']);

// ─── Batches ─────────────────────────────────────────────────────────────────

$router->get('/branch/batches', 'BranchAdmin\Controllers\BranchBatchController@index', ['branch_admin']);
$router->get('/branch/batches/create', 'BranchAdmin\Controllers\BranchBatchController@create', ['branch_admin']);
$router->post('/branch/batches', 'BranchAdmin\Controllers\BranchBatchController@store', ['branch_admin']);
$router->post('/branch/batches/{id}/delete', 'BranchAdmin\Controllers\BranchBatchController@delete', ['branch_admin']);

// ─── Fee Collection ──────────────────────────────────────────────────────────

$router->get('/branch/fees', 'BranchAdmin\Controllers\BranchFeeController@index', ['branch_admin']);
$router->get('/branch/fees/collect', 'BranchAdmin\Controllers\BranchFeeController@collect', ['branch_admin']);
$router->post('/branch/fees/store', 'BranchAdmin\Controllers\BranchFeeController@store', ['branch_admin']);
$router->get('/branch/fees/receipt/{id}', 'BranchAdmin\Controllers\BranchFeeController@receipt', ['branch_admin']);
$router->get('/branch/fees/reports', 'BranchAdmin\Controllers\BranchFeeController@reports', ['branch_admin']);
$router->get('/branch/fees/get-course-fee', 'BranchAdmin\Controllers\BranchFeeController@getCourseFee', ['branch_admin']);

// ─── Course Fees ─────────────────────────────────────────────────────────────

$router->get('/branch/course-fees', 'BranchAdmin\Controllers\BranchCourseFeeController@index', ['branch_admin']);

// ─── Wallet ──────────────────────────────────────────────────────────────────

$router->get('/branch/wallet', 'BranchAdmin\Controllers\BranchWalletController@index', ['branch_admin']);

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

$router->get('/branch/exams', 'BranchAdmin\Controllers\BranchExamController@index', ['branch_admin']);
$router->get('/branch/exams/create', 'BranchAdmin\Controllers\BranchExamController@create', ['branch_admin']);
$router->post('/branch/exams', 'BranchAdmin\Controllers\BranchExamController@store', ['branch_admin']);
$router->get('/branch/exams/{id}/edit', 'BranchAdmin\Controllers\BranchExamController@edit', ['branch_admin']);
$router->post('/branch/exams/{id}', 'BranchAdmin\Controllers\BranchExamController@update', ['branch_admin']);
$router->post('/branch/exams/{id}/delete', 'BranchAdmin\Controllers\BranchExamController@delete', ['branch_admin']);
$router->get('/branch/exams/{id}/questions', 'BranchAdmin\Controllers\BranchExamController@questions', ['branch_admin']);
$router->post('/branch/exams/{id}/questions', 'BranchAdmin\Controllers\BranchExamController@storeQuestion', ['branch_admin']);
$router->get('/branch/exams/download-template', 'BranchAdmin\Controllers\BranchExamController@downloadTemplate', ['branch_admin']);

// ─── Exam Portal (Student-facing) ────────────────────────────────────────────

$router->get('/branch/exam-portal', 'BranchAdmin\Controllers\BranchExamPortalController@index', ['branch_admin']);

// ─── Exam Results ────────────────────────────────────────────────────────────

$router->get('/branch/exam-results', 'BranchAdmin\Controllers\BranchExamResultController@index', ['branch_admin']);
$router->get('/branch/exam-results/{id}', 'BranchAdmin\Controllers\BranchExamResultController@show', ['branch_admin']);
$router->get('/branch/exam-results/{id}/edit', 'BranchAdmin\Controllers\BranchExamResultController@edit', ['branch_admin']);
$router->post('/branch/exam-results/{id}', 'BranchAdmin\Controllers\BranchExamResultController@update', ['branch_admin']);
$router->get('/branch/exam-results/{id}/certificate', 'BranchAdmin\Controllers\BranchExamResultController@certificate', ['branch_admin']);
$router->get('/branch/exam-results/{id}/marksheet', 'BranchAdmin\Controllers\BranchExamResultController@marksheet', ['branch_admin']);

// ─── Results ─────────────────────────────────────────────────────────────────

$router->get('/branch/results', 'BranchAdmin\Controllers\BranchResultController@index', ['branch_admin']);
$router->get('/branch/results/create', 'BranchAdmin\Controllers\BranchResultController@create', ['branch_admin']);
$router->post('/branch/results', 'BranchAdmin\Controllers\BranchResultController@store', ['branch_admin']);
$router->get('/branch/results/{id}', 'BranchAdmin\Controllers\BranchResultController@show', ['branch_admin']);

// ─── Admit Cards ─────────────────────────────────────────────────────────────

$router->get('/branch/admit-cards', 'BranchAdmin\Controllers\BranchAdmitCardController@index', ['branch_admin']);
$router->post('/branch/admit-cards/generate', 'BranchAdmin\Controllers\BranchAdmitCardController@generate', ['branch_admin']);
$router->get('/branch/admit-cards/{id}', 'BranchAdmin\Controllers\BranchAdmitCardController@show', ['branch_admin']);
$router->get('/branch/admit-cards/{id}/view', 'BranchAdmin\Controllers\BranchAdmitCardController@show', ['branch_admin']);

// ─── ID Cards ────────────────────────────────────────────────────────────────

$router->get('/branch/id-cards', 'BranchAdmin\Controllers\BranchIdCardController@index', ['branch_admin']);
$router->post('/branch/id-cards/generate', 'BranchAdmin\Controllers\BranchIdCardController@generate', ['branch_admin']);
$router->get('/branch/id-cards/{id}', 'BranchAdmin\Controllers\BranchIdCardController@show', ['branch_admin']);
$router->get('/branch/id-cards/{id}/view', 'BranchAdmin\Controllers\BranchIdCardController@show', ['branch_admin']);

// ─── Facilities & Faculty ────────────────────────────────────────────────────

$router->get('/branch/facilities', 'BranchAdmin\Controllers\BranchFacilityController@index', ['branch_admin']);
$router->get('/branch/facilities/reviews', 'BranchAdmin\Controllers\BranchFacilityController@reviews', ['branch_admin']);

// ─── Documents (Old system) ──────────────────────────────────────────────────

$router->get('/branch/documents', 'BranchAdmin\Controllers\BranchDocumentController@index', ['branch_admin']);
$router->get('/branch/documents/create', 'BranchAdmin\Controllers\BranchDocumentController@create', ['branch_admin']);
$router->post('/branch/documents', 'BranchAdmin\Controllers\BranchDocumentController@store', ['branch_admin']);
$router->get('/branch/documents/{id}', 'BranchAdmin\Controllers\BranchDocumentController@show', ['branch_admin']);
$router->get('/branch/documents/{id}/download', 'BranchAdmin\Controllers\BranchDocumentController@download', ['branch_admin']);
$router->post('/branch/documents/{id}/delete', 'BranchAdmin\Controllers\BranchDocumentController@delete', ['branch_admin']);

// ═══════════════════════════════════════════════════════════════════════════════
// ─── Certificate & Marksheet Generation (Phase 5) ───────────────────────────
// ═══════════════════════════════════════════════════════════════════════════════

$router->get('/branch/cert-gen', 'BranchAdmin\Controllers\BranchCertGenController@index', ['branch_admin']);
$router->get('/branch/cert-gen/new', 'BranchAdmin\Controllers\BranchCertGenController@createStudent', ['branch_admin']);
$router->post('/branch/cert-gen/preview', 'BranchAdmin\Controllers\BranchCertGenController@previewStudent', ['branch_admin']);
$router->post('/branch/cert-gen/store-student', 'BranchAdmin\Controllers\BranchCertGenController@storeStudent', ['branch_admin']);
$router->get('/branch/cert-gen/student/{studentId}', 'BranchAdmin\Controllers\BranchCertGenController@createResult', ['branch_admin']);
$router->post('/branch/cert-gen/student/{studentId}/store-result', 'BranchAdmin\Controllers\BranchCertGenController@storeResult', ['branch_admin']);

// Download single PDF
$router->get('/branch/cert-gen/{certId}/download', 'BranchAdmin\Controllers\BranchCertGenController@download', ['branch_admin']);

// Download combined (cert + marksheet for same student)
$router->get('/branch/cert-gen/{certId}/download-combined', 'BranchAdmin\Controllers\BranchCertGenController@downloadCombined', ['branch_admin']);

// Bulk download (multiple certificates in one PDF)
$router->post('/branch/cert-gen/bulk-download', 'BranchAdmin\Controllers\BranchCertGenController@bulkDownload', ['branch_admin']);

// Edit & Delete result
$router->get('/branch/cert-gen/edit/{id}', 'BranchAdmin\Controllers\BranchResultEditController@edit', ['branch_admin']);
$router->post('/branch/cert-gen/update/{id}', 'BranchAdmin\Controllers\BranchResultEditController@update', ['branch_admin']);
$router->get('/branch/cert-gen/delete/{id}', 'BranchAdmin\Controllers\BranchResultEditController@confirmDelete', ['branch_admin']);
$router->post('/branch/cert-gen/delete/{id}', 'BranchAdmin\Controllers\BranchResultEditController@delete', ['branch_admin']);

// ═══════════════════════════════════════════════════════════════════════════════
// ─── Print Queue (Bulk Printing with Filters) ───────────────────────────────
// ═══════════════════════════════════════════════════════════════════════════════

$router->get('/branch/print-queue', 'BranchAdmin\Controllers\BranchPrintQueueController@index', ['branch_admin']);
$router->post('/branch/print-queue/bulk-download', 'BranchAdmin\Controllers\BranchPrintQueueController@bulkDownload', ['branch_admin']);

// ─── Branch Wallet ───────────────────────────────────────────────────────────
$router->get('/branch/wallet', 'BranchAdmin\Controllers\BranchWalletController@index', ['branch_admin']);
$router->get('/branch/wallet/history', 'BranchAdmin\Controllers\BranchWalletController@history', ['branch_admin']);

// ─── Branch Courses & Fees (Branch-specific override) ────────────────────────
$router->get('/branch/courses', 'BranchAdmin\Controllers\BranchCourseController@index', ['branch_admin']);
$router->post('/branch/courses/update', 'BranchAdmin\Controllers\BranchCourseController@update', ['branch_admin']);
