<?php

use CodeIgniter\Router\RouteCollection;

/** @var RouteCollection $routes */
$routes->get('/', 'AuthController::index');
$routes->get('/login', 'AuthController::index');
$routes->post('/auth/login', 'AuthController::login');
$routes->get('/auth/logout', 'AuthController::logout');

$routes->group('', ['filter' => 'auth'], static function ($routes) {
    // Admin routes
    $routes->get('/admin', 'AdminController::index', ['filter' => 'role:admin']);
    $routes->get('/wali', 'WaliController::index', ['filter' => 'role:wali']);
    $routes->post('/wali/submit', 'WaliController::submit', ['filter' => 'role:wali']);
    $routes->get('/kesantrian', 'KesantrianController::index', ['filter' => 'role:kesantrian,admin']);
    $routes->get('/kesantrian/permits', 'KesantrianController::permits', ['filter' => 'role:kesantrian,admin']);
    $routes->post('/kesantrian/approve/(:num)', 'KesantrianController::approve/$1', ['filter' => 'role:kesantrian,admin']);

    // User Management routes (Admin & Kesantrian)
    $routes->get('/users', 'UserController::index', ['filter' => 'role:admin,kesantrian']);
    $routes->post('/users/store', 'UserController::store', ['filter' => 'role:admin,kesantrian']);
    $routes->post('/users/update/(:num)', 'UserController::update/$1', ['filter' => 'role:admin,kesantrian']);
    $routes->get('/users/delete/(:num)', 'UserController::delete/$1', ['filter' => 'role:admin,kesantrian']);

    // Reports routes
    $routes->get('/reports', 'ReportController::index', ['filter' => 'role:admin,kesantrian']);

    // Santri Data routes (Admin only)
    $routes->get('/santri', 'SantriController::index', ['filter' => 'role:kesantrian,admin']);
    $routes->post('/santri/store', 'SantriController::store', ['filter' => 'role:kesantrian,admin']);
    $routes->post('/santri/update/(:num)', 'SantriController::update/$1', ['filter' => 'role:kesantrian,admin']);
    $routes->get('/santri/delete/(:num)', 'SantriController::delete/$1', ['filter' => 'role:kesantrian,admin']);
    $routes->get('/satpam', 'SatpamController::index', ['filter' => 'role:satpam']);
    $routes->get('/satpam/scan', 'SatpamController::scan', ['filter' => 'role:satpam']);
    $routes->get('/satpam/permits', 'SatpamController::permits', ['filter' => 'role:satpam']);
    $routes->post('/satpam/scan', 'SatpamController::process_scan', ['filter' => 'role:satpam']);
});
