<?php

use CodeIgniter\Router\RouteCollection;

/**
 * @var RouteCollection $routes
 */

// Home/Root
$routes->get('/', 'Auth::login');

// Authentication
$routes->group('auth', function ($routes) {
    $routes->get('login', 'Auth::login');
    $routes->post('loginProcess', 'Auth::loginProcess');
    $routes->get('register', 'Auth::register');
    $routes->post('registerProcess', 'Auth::registerProcess');
    $routes->get('logout', 'Auth::logout');
    $routes->get('profile', 'Auth::profile');
    $routes->post('profile/update', 'Auth::updateProfile');
});

// Admin Dashboard
$routes->group('admin', ['filter' => ['auth', 'role_admin']], function ($routes) {
    $routes->get('dashboard', 'Admin\Dashboard::index');
    $routes->get('settings', 'Admin\Settings::index');
    $routes->get('settings/backup', 'Admin\Settings::backup');
    $routes->post('settings/update', 'Admin\Settings::update');

    // Pegawai Management
    $routes->get('pegawai', 'Admin\Pegawai::index');
    $routes->get('pegawai/add', 'Admin\Pegawai::add');
    $routes->post('pegawai/processAdd', 'Admin\Pegawai::processAdd');
    $routes->get('pegawai/edit/(:num)', 'Admin\Pegawai::edit/$1');
    $routes->post('pegawai/processEdit/(:num)', 'Admin\Pegawai::processEdit/$1');
    $routes->get('pegawai/delete/(:num)', 'Admin\Pegawai::delete/$1');
    $routes->post('pegawai/import', 'Admin\Pegawai::import');
    $routes->get('pegawai/template', 'Admin\Pegawai::template');

    // User Management
    $routes->get('user', 'Admin\User::index');
    $routes->get('user/add', 'Admin\User::add');
    $routes->post('user/processAdd', 'Admin\User::processAdd');
    $routes->get('user/edit/(:num)', 'Admin\User::edit/$1');
    $routes->post('user/processEdit/(:num)', 'Admin\User::processEdit/$1');
    $routes->get('user/delete/(:num)', 'Admin\User::delete/$1');
    $routes->get('user/toggle/(:num)', 'Admin\User::toggle/$1');
    $routes->get('user/setStatus/(:num)/(:num)', 'Admin\User::setStatus/$1/$2');

    // Monitoring All Pengajuan
    $routes->get('pengajuan', 'Admin\Pengajuan::index');

    // Laporan
    $routes->get('laporan', 'Admin\Laporan::index');

    // Chatbot WA
    $routes->get('chatbot', 'Admin\Chatbot::index');
    $routes->post('chatbot/test', 'Admin\Chatbot::test');
    $routes->get('chatbot/delete/(:num)', 'Admin\Chatbot::delete/$1');
    $routes->get('chatbot/clear', 'Admin\Chatbot::clear');
});

// Keuangan Group (using same controllers but different prefix)
$routes->group('keuangan', ['filter' => ['auth', 'role_admin']], function ($routes) {
    $routes->get('laporan', 'Admin\Laporan::index');
    $routes->addRedirect('pengajuan', 'keuangan/laporan');
});

// Verifikator Dashboard
$routes->group('verifikator', ['filter' => 'auth'], function ($routes) {
    $routes->get('dashboard', 'Verifikator\Dashboard::index');
    $routes->get('detail/(:num)', 'Verifikator\Dashboard::detail/$1');
    $routes->post('updateStatus/(:num)', 'Verifikator\Dashboard::updateStatus/$1');
});

// User ASN Dashboard
$routes->group('user', ['filter' => 'auth'], function ($routes) {
    $routes->get('dashboard', 'User\Dashboard::index');
    $routes->get('pengajuan', 'User\Pengajuan::index');
    $routes->get('riwayat', 'User\Pengajuan::riwayat');
    $routes->get('pengajuan/riwayat_detail/(:num)', 'User\Pengajuan::riwayat_detail/$1');
    $routes->get('pengajuan/edit/(:num)', 'User\Pengajuan::edit/$1');
    $routes->post('pengajuan/update/(:num)', 'User\Pengajuan::update/$1');
    $routes->post('pengajuan/process', 'User\Pengajuan::process');
    $routes->post('pengajuan/submit', 'User\Pengajuan::submit');
    $routes->get('pengajuan/submit', 'User\Pengajuan::submit');
    $routes->get('pengajuan/search_pegawai/(:segment)', 'User\Pengajuan::search_pegawai/$1');
    $routes->get('pengajuan/check_existing_docs/(:segment)', 'User\Pengajuan::check_existing_docs/$1');
});

// API Routes
$routes->get('api/pegawai/(:segment)', 'User\Pengajuan::search_pegawai/$1');

