<?php

use CodeIgniter\Router\RouteCollection;

/**
 * @var RouteCollection $routes
 */
$routes->get('/', static fn () => redirect()->to('admin/login'));

$routes->group('admin', ['namespace' => 'App\Controllers\Admin'], static function ($routes) {
    $routes->get('login', 'Auth::login');
    $routes->post('login', 'Auth::attempt');
    $routes->get('logout', 'Auth::logout');
});

$routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'authadmin'], static function ($routes) {
    $routes->get('/', 'Dashboard::index');
    $routes->get('pegawai', 'Pegawai::index');
    $routes->get('pegawai/create', 'Pegawai::create');
    $routes->post('pegawai/store', 'Pegawai::store');
    $routes->get('pegawai/edit/(:num)', 'Pegawai::edit/$1');
    $routes->post('pegawai/update/(:num)', 'Pegawai::update/$1');
    $routes->post('pegawai/delete/(:num)', 'Pegawai::delete/$1');
    $routes->post('pegawai/reset/(:num)', 'Pegawai::reset/$1');
    $routes->get('presensi', 'Presensi::index');
    $routes->get('presensi/export', 'Presensi::exportCsv');
    $routes->get('presensi/export-xlsx', 'Presensi::exportXlsx');
    $routes->get('presensi/foto/(:segment)/(:segment)', 'Presensi::foto/$1/$2');
    $routes->get('presensi/detail/(:num)', 'Presensi::detail/$1');
    $routes->get('laporan', 'Laporan::index');
    $routes->get('laporan/cuti', 'Laporan::cuti');
    $routes->get('perusahaan/kantor', 'Company::kantor');
    $routes->get('perusahaan/unit_kerja', 'Company::unitKerja');
    $routes->get('perusahaan/golongan', 'Company::golongan');
    $routes->get('perusahaan/jabatan', 'Company::jabatan');
    $routes->get('perusahaan/berita', 'Company::berita');
    $routes->post('perusahaan/kantor/save', 'Company::kantorSave');
    $routes->post('perusahaan/kantor/delete/(:num)', 'Company::kantorDelete/$1');
    $routes->post('perusahaan/unit_kerja/save', 'Company::unitKerjaSave');
    $routes->post('perusahaan/unit_kerja/delete/(:num)', 'Company::unitKerjaDelete/$1');
    $routes->post('perusahaan/golongan/save', 'Company::golonganSave');
    $routes->post('perusahaan/golongan/delete/(:num)', 'Company::golonganDelete/$1');
    $routes->post('perusahaan/jabatan/save', 'Company::jabatanSave');
    $routes->post('perusahaan/jabatan/delete/(:num)', 'Company::jabatanDelete/$1');
    $routes->post('perusahaan/berita/save', 'Company::beritaSave');
    $routes->post('perusahaan/berita/delete/(:num)', 'Company::beritaDelete/$1');
    $routes->get('presensi/lapangan', 'Presensi::lapangan');
    $routes->get('presensi/lembur', 'Presensi::lembur');
    $routes->get('presensi/libur', 'Presensi::libur');
    $routes->get('presensi/jadwal', 'Presensi::jadwal');
    $routes->get('presensi/aktivitas', 'Presensi::aktivitas');
    $routes->post('presensi/lapangan/save', 'Presensi::lapanganSave');
    $routes->post('presensi/lapangan/delete/(:num)', 'Presensi::lapanganDelete/$1');
    $routes->post('presensi/lembur/save', 'Presensi::lemburSave');
    $routes->post('presensi/lembur/delete/(:num)', 'Presensi::lemburDelete/$1');
    $routes->post('presensi/libur/save', 'Presensi::liburSave');
    $routes->post('presensi/libur/delete/(:num)', 'Presensi::liburDelete/$1');
    $routes->post('presensi/jadwal/save', 'Presensi::jadwalSave');
    $routes->post('presensi/jadwal/delete/(:num)', 'Presensi::jadwalDelete/$1');
    $routes->post('presensi/aktivitas/delete/(:num)', 'Presensi::aktivitasDelete/$1');
    $routes->get('panel/users', 'Panel::users');
    $routes->get('panel/groups', 'Panel::groups');
    $routes->get('panel/groups/create', 'Panel::groupCreate');
    $routes->post('panel/groups/store', 'Panel::groupStore');
    $routes->get('panel/groups/edit/(:num)', 'Panel::groupEdit/$1');
    $routes->post('panel/groups/update/(:num)', 'Panel::groupUpdate/$1');
    $routes->post('panel/groups/delete/(:num)', 'Panel::groupDelete/$1');
    $routes->get('panel/users/create', 'Panel::userCreate');
    $routes->post('panel/users/store', 'Panel::userStore');
    $routes->get('panel/users/edit/(:num)', 'Panel::userEdit/$1');
    $routes->post('panel/users/update/(:num)', 'Panel::userUpdate/$1');
    $routes->get('panel/users/reset/(:num)', 'Panel::userReset/$1');
    $routes->post('panel/users/reset_password/(:num)', 'Panel::userResetPassword/$1');
    $routes->get('util/backup', 'Util::backup');
    $routes->post('util/backup/run', 'Util::backupRun');
    $routes->post('util/backup/delete/(:segment)', 'Util::backupDelete/$1');
    $routes->get('util/backup/download/(:segment)', 'Util::backupDownload/$1');
    $routes->get('cuti', 'Cuti::index');
    $routes->get('cuti/dokumen/(:segment)', 'Cuti::dokumen/$1');
    $routes->get('cuti/detail/(:num)', 'Cuti::detail/$1');
    $routes->post('cuti/approve/(:num)', 'Cuti::approve/$1');
    $routes->post('cuti/reject/(:num)', 'Cuti::reject/$1');
});

$routes->group('api/admin', ['namespace' => 'App\Controllers\Api\Admin'], static function ($routes) {
    $routes->get('references', 'ReferenceController::index');
    $routes->get('dashboard', 'DashboardController::index');
    $routes->get('pegawai', 'PegawaiController::index');
    $routes->get('pegawai/(:num)', 'PegawaiController::show/$1');
    $routes->post('pegawai/create', 'PegawaiController::create');
    $routes->post('pegawai/update', 'PegawaiController::update');
    $routes->post('pegawai/delete', 'PegawaiController::delete');
    $routes->post('pegawai/reset_password', 'PegawaiController::resetPassword');
    $routes->get('presensi', 'PresensiController::index');
    $routes->get('presensi/(:num)', 'PresensiController::show/$1');
    $routes->get('laporan', 'LaporanController::index');
    $routes->get('cuti', 'CutiController::index');
    $routes->get('cuti/(:num)', 'CutiController::show/$1');
    $routes->post('cuti/approve', 'CutiController::approve');
    $routes->post('cuti/reject', 'CutiController::reject');
    $routes->get('laporan/cuti', 'LaporanController::cutiRentang');
    $routes->get('company/kantor', 'CompanyDataApiController::kantor');
    $routes->post('company/kantor/save', 'CompanyDataApiController::kantorSave');
    $routes->post('company/kantor/delete/(:num)', 'CompanyDataApiController::kantorDelete/$1');
    $routes->get('company/unit_kerja', 'CompanyDataApiController::unitKerja');
    $routes->post('company/unit_kerja/save', 'CompanyDataApiController::unitKerjaSave');
    $routes->post('company/unit_kerja/delete/(:num)', 'CompanyDataApiController::unitKerjaDelete/$1');
    $routes->get('company/golongan', 'CompanyDataApiController::golongan');
    $routes->post('company/golongan/save', 'CompanyDataApiController::golonganSave');
    $routes->post('company/golongan/delete/(:num)', 'CompanyDataApiController::golonganDelete/$1');
    $routes->get('company/jabatan', 'CompanyDataApiController::jabatan');
    $routes->post('company/jabatan/save', 'CompanyDataApiController::jabatanSave');
    $routes->post('company/jabatan/delete/(:num)', 'CompanyDataApiController::jabatanDelete/$1');
    $routes->get('company/berita', 'CompanyDataApiController::berita');
    $routes->post('company/berita/save', 'CompanyDataApiController::beritaSave');
    $routes->post('company/berita/delete/(:num)', 'CompanyDataApiController::beritaDelete/$1');
    $routes->get('presensi/dilapangan', 'PresensiToolsApiController::dilapangan');
    $routes->post('presensi/dilapangan/save', 'PresensiToolsApiController::dilapanganSave');
    $routes->post('presensi/dilapangan/delete/(:num)', 'PresensiToolsApiController::dilapanganDelete/$1');
    $routes->get('presensi/lembur', 'PresensiToolsApiController::lembur');
    $routes->post('presensi/lembur/save', 'PresensiToolsApiController::lemburSave');
    $routes->post('presensi/lembur/delete/(:num)', 'PresensiToolsApiController::lemburDelete/$1');
    $routes->get('presensi/libur', 'PresensiToolsApiController::libur');
    $routes->post('presensi/libur/save', 'PresensiToolsApiController::liburSave');
    $routes->post('presensi/libur/delete/(:num)', 'PresensiToolsApiController::liburDelete/$1');
    $routes->get('presensi/jadwal', 'PresensiToolsApiController::jadwal');
    $routes->post('presensi/jadwal/save', 'PresensiToolsApiController::jadwalSave');
    $routes->post('presensi/jadwal/delete/(:num)', 'PresensiToolsApiController::jadwalDelete/$1');
    $routes->get('presensi/aktivitas', 'PresensiToolsApiController::aktivitas');
    $routes->post('presensi/aktivitas/delete/(:num)', 'PresensiToolsApiController::aktivitasDelete/$1');
    $routes->get('panel/users', 'PanelUsersApiController::users');
    $routes->get('panel/groups', 'PanelUsersApiController::groups');
    $routes->post('panel/groups/create', 'PanelUsersApiController::groupCreate');
    $routes->post('panel/groups/update/(:num)', 'PanelUsersApiController::groupUpdate/$1');
    $routes->post('panel/groups/delete/(:num)', 'PanelUsersApiController::groupDelete/$1');
    $routes->get('panel/users/(:num)', 'PanelUsersApiController::userShow/$1');
    $routes->post('panel/users/create', 'PanelUsersApiController::userCreate');
    $routes->post('panel/users/update/(:num)', 'PanelUsersApiController::userUpdate/$1');
    $routes->post('panel/users/reset_password/(:num)', 'PanelUsersApiController::userResetPassword/$1');
    $routes->get('backup', 'DatabaseBackupApiController::index');
    $routes->post('backup/run', 'DatabaseBackupApiController::run');
    $routes->post('backup/delete/(:segment)', 'DatabaseBackupApiController::delete/$1');
});

/*
 * --------------------------------------------------------------------
 * API mobile (port CI3 application/controllers/Json.php)
 * --------------------------------------------------------------------
 * Rute utama: /api/mobile/{method}
 * Alias kompatibilitas path CI3: /json/{method} (POST)
 */
$mobileJsonRoutes = static function ($routes): void {
    $routes->post('login_w_token', 'MobileJsonController::login_w_token');
    $routes->post('login', 'MobileJsonController::login');
    $routes->post('profil', 'MobileJsonController::profil');
    $routes->post('save_cuti', 'MobileJsonController::save_cuti');
    $routes->post('batalkan_cuti', 'MobileJsonController::batalkan_cuti');
    $routes->post('save_aktifitas', 'MobileJsonController::save_aktifitas');
    $routes->post('save_masuk', 'MobileJsonController::save_masuk');
    $routes->post('save_pulang', 'MobileJsonController::save_pulang');
    $routes->post('save_istirahat', 'MobileJsonController::save_istirahat');
    $routes->post('presensi_today', 'MobileJsonController::presensi_today');
    $routes->post('presensi', 'MobileJsonController::presensi');
    $routes->post('daftar_today', 'MobileJsonController::daftar_today');
    $routes->post('berita', 'MobileJsonController::berita');
    $routes->post('cuti', 'MobileJsonController::cuti');
    $routes->post('lembur', 'MobileJsonController::lembur');
    $routes->post('libur', 'MobileJsonController::libur');
    $routes->post('aktifitas', 'MobileJsonController::aktifitas');
    $routes->post('save_pp', 'MobileJsonController::save_pp');
    $routes->post('save_password', 'MobileJsonController::save_password');
};

$routes->group('api/mobile', ['namespace' => 'App\Controllers\Api'], $mobileJsonRoutes);
$routes->group('json', ['namespace' => 'App\Controllers\Api'], $mobileJsonRoutes);
