<?php

use CodeIgniter\Router\RouteCollection;
use Config\ModuleLoader;

/**
 * @var RouteCollection $routes
 */

// Root: redirect ke halaman login dashboard
$routes->get('/', static function () {
    return redirect()->to('/login');
});

// Load module routes automatically
$moduleLoader = new ModuleLoader();
$moduleLoader->loadModuleRoutes($routes);

// API: users (admin only) — list by role, create/update/delete for teachers
$routes->get('api/users', '\App\Modules\Auth\Controllers\UserController::index', ['filter' => 'admin_only']);
$routes->post('api/users', '\App\Modules\Auth\Controllers\UserController::store', ['filter' => 'admin_only']);
$routes->put('api/users/(:num)', '\App\Modules\Auth\Controllers\UserController::update/$1', ['filter' => 'admin_only']);
$routes->delete('api/users/(:num)', '\App\Modules\Auth\Controllers\UserController::delete/$1', ['filter' => 'admin_only']);

// Web dashboard (requires authenticated session)
$routes->get('login', 'LoginController::index');
$routes->post('logout', 'LogoutController::index');
$routes->get('dashboard', 'DashboardPageController::index', ['filter' => 'dashboard_page_auth']);
$routes->get('dashboard/profile', 'DashboardPageController::profile', ['filter' => 'dashboard_page_auth']);
$routes->get('dashboard/attendance/reports', 'DashboardPageController::attendanceReports', ['filter' => 'dashboard_page_auth']);
    $routes->get('dashboard/attendance/report/(:num)', 'DashboardPageController::attendanceReport/$1', ['filter' => 'dashboard_page_auth']);
$routes->get('dashboard/schedule/today', 'DashboardPageController::scheduleToday', ['filter' => 'dashboard_page_auth']);
$routes->get('dashboard/discipline', 'DashboardPageController::discipline', ['filter' => 'dashboard_page_auth']);
$routes->get('dashboard/parent', 'DashboardPageController::parent', ['filter' => 'dashboard_page_auth']);
$routes->get('dashboard/academic/settings', 'DashboardAcademicController::academicSettings', ['filter' => 'dashboard_admin_page']);
$routes->get('dashboard/academic/classes', 'DashboardAcademicController::classes', ['filter' => 'dashboard_admin_page']);
$routes->get('dashboard/academic/subjects', 'DashboardAcademicController::subjects', ['filter' => 'dashboard_admin_page']);
$routes->get('dashboard/academic/teachers', 'DashboardAcademicController::teachers', ['filter' => 'dashboard_admin_page']);
$routes->get('dashboard/academic/lesson-slots', 'DashboardAcademicController::lessonSlots', ['filter' => 'dashboard_admin_page']);
$routes->get('dashboard/academic/students', 'DashboardAcademicController::students', ['filter' => 'dashboard_admin_page']);
$routes->get('dashboard/academic/dapodik', 'DashboardAcademicController::dapodik', ['filter' => 'dashboard_admin_page']);
$routes->get('dashboard/academic/schedule-builder', 'DashboardAcademicController::scheduleBuilderIndex', ['filter' => 'dashboard_admin_page']);
    $routes->get('dashboard/academic/schedule-builder/(:num)', 'DashboardAcademicController::scheduleBuilder/$1', ['filter' => 'dashboard_admin_page']);
$routes->get('dashboard/academic/discipline-settings', 'DashboardAcademicController::disciplineSettings', ['filter' => 'dashboard_admin_page']);
$routes->get('dashboard/presence-settings', 'DashboardPageController::presenceSettings', ['filter' => 'dashboard_admin_page']);
$routes->get('dashboard/devices', 'DashboardPageController::devices', ['filter' => 'dashboard_admin_page']);

// Main application routes can be defined here
// Module routes are automatically loaded from app/Modules/*/Routes.php
