<?php

use CodeIgniter\Router\RouteCollection;

/** @var RouteCollection $routes */
// Redirect default ke halaman login
$routes->addRedirect('/', 'login');

// ==========================================
// ROUTES AUTENTIKASI (Bebas Akses)
// ==========================================
$routes->get('/login', 'Auth::login');
$routes->post('/login', 'Auth::attemptLogin');
$routes->get('/logout', 'Auth::logout');

// ==========================================
// ROUTES PROTECTED (Wajib Login & Sesuai Role)
// ==========================================

$routes->group('admin', ['filter' => 'auth:Admin'], static function ($routes) {
    // Redirect /admin ke /admin/home
    $routes->addRedirect('/', 'admin/home');
    // Rute utama untuk dashboard Admin
    $routes->get('home', 'AdminController::index');
});

// 2. Group Mahasiswa
$routes->group('mahasiswa', ['filter' => 'auth:Mahasiswa'], static function ($routes) {
    // Redirect /mahasiswa ke /mahasiswa/home
    $routes->addRedirect('/', 'mahasiswa/home');
    // Rute utama untuk dashboard Mahasiswa
    $routes->get('home', 'MahasiswaController::index');
});

// 3. Group TU
$routes->group('tu', ['filter' => 'auth:TU'], static function ($routes) {
    // Redirect /tu ke /tu/home
    $routes->addRedirect('/', 'tu/home');
    $routes->get('home', 'TuController::index');
});

// 4. Group Dosen
$routes->group('dosen', ['filter' => 'auth:Dosen'], static function ($routes) {
    // Redirect /dosen ke /dosen/home
    $routes->addRedirect('/', 'dosen/home');
    $routes->get('home', 'DosenController::index');
});

// 5. Group Keuangan
$routes->group('keuangan', ['filter' => 'auth:Keuangan'], static function ($routes) {
    // Redirect /keuangan ke /keuangan/home
    $routes->addRedirect('/', 'keuangan/home');
    $routes->get('home', 'KeuanganController::index');
});

// 6. Group Administrasi Keuangan
$routes->group('administrasi-keuangan', ['filter' => 'auth:Administrasi Keuangan'], static function ($routes) {
    // Redirect /administrasi-keuangan ke /administrasi-keuangan/home
    $routes->addRedirect('/', 'administrasi-keuangan/home');
    $routes->get('home', 'AdminKeuanganController::index');
});

// 7. Group Administrator PMB
$routes->group('admin-pmb', ['filter' => 'auth:Administrator PMB'], static function ($routes) {
    // Redirect /admin-pmb ke /admin-pmb/home
    $routes->addRedirect('/', 'admin-pmb/home');
    $routes->get('home', 'AdminPmbController::index');
});

// 8. Group Administrator Prodi
$routes->group('admin-prodi', ['filter' => 'auth:Administrator Prodi'], static function ($routes) {
    // Redirect /admin-prodi ke /admin-prodi/home
    $routes->addRedirect('/', 'admin-prodi/home');
    $routes->get('home', 'AdminProdiController::index');
});

// 9. Group Dosen Belum-NIDN
$routes->group('dosen-non-nidn', ['filter' => 'auth:Dosen Belum-NIDN'], static function ($routes) {
    // Redirect /dosen-non-nidn ke /dosen-non-nidn/home
    $routes->addRedirect('/', 'dosen-non-nidn/home');
    $routes->get('home', 'DosenNonNidnController::index');
});

// 10. Group Pimpinan
$routes->group('pimpinan', ['filter' => 'auth:Pimpinan'], static function ($routes) {
    // Redirect /pimpinan ke /pimpinan/home
    $routes->addRedirect('/', 'pimpinan/home');
    $routes->get('home', 'PimpinanController::index');
});
