<?php

use CodeIgniter\Router\RouteCollection;

/**
 * @var RouteCollection $routes
 */

// ===================================================================
// RUTE JALUR PUBLIK (Bisa Diakses Siapapun / Petani Tanpa Login)
// ===================================================================
$routes->get('/', 'Home::index'); // Portal utama untuk cek e-RDKK & pupuk masuk

// Rute Otentikasi Petugas
$routes->get('/auth', 'Auth::index');
$routes->post('/auth/proses_login', 'Auth::proses_login');
$routes->get('/auth/logout', 'Auth::logout');
$routes->get('/auth/setup_admin', 'Auth::setup_admin');
$routes->post('/auth/register', 'Auth::register');
$routes->get('/auth/reset_admin', 'Auth::reset_admin');

// Fitur Lupa Password
$routes->get('/auth/lupa_password', 'Auth::lupa_password');
$routes->post('/auth/kirim_token_simulasi', 'Auth::kirim_token_simulasi');
$routes->get('/auth/form_reset', 'Auth::form_reset');
$routes->post('/auth/proses_reset', 'Auth::proses_reset');

// Manajemen Pengguna (User)
$routes->get('/user', 'User::index');
$routes->post('/user/simpan', 'User::simpan');
$routes->post('/user/update/(:num)', 'User::update/$1');
$routes->get('/user/hapus/(:num)', 'User::hapus/$1');


// ===================================================================
// GRUP RUTE TERPROTEKSI (Wajib Lolos Filter Login 'auth')
// ===================================================================
$routes->group('', ['filter' => 'auth'], function ($routes) {
    
    // PERBAIKAN: Halaman utama petugas internal dialihkan ke fungsi dashboard
    $routes->get('/dashboard', 'Home::dashboard');

    // Manajemen Data Petani
    $routes->get('/petani', 'Petani::index');
    $routes->post('/petani/simpan', 'Petani::simpan');
    $routes->post('/petani/update/(:num)', 'Petani::update/$1');
    $routes->get('/petani/hapus/(:num)', 'Petani::hapus/$1');

    // Manajemen Data Stok Gudang Pupuk
    $routes->get('/pupuk', 'Pupuk::index');
    $routes->post('/pupuk/simpan', 'Pupuk::simpan');
    $routes->post('/pupuk/update/(:num)', 'Pupuk::update/$1');
    $routes->get('/pupuk/hapus/(:num)', 'Pupuk::hapus/$1');

    // Manajemen Alokasi e-RDKK
    $routes->get('/alokasi', 'Alokasi::index');
    $routes->post('/alokasi/simpan', 'Alokasi::simpan');
    $routes->post('/alokasi/generate_otomatis', 'Alokasi::generate_otomatis');
    $routes->get('/alokasi/hapus/(:num)', 'Alokasi::hapus/$1');
    $routes->get('/alokasi/laporan', 'Alokasi::laporan');
    $routes->get('/alokasi/cetak', 'Alokasi::cetak');

    // Manajemen Transaksi Penebusan Pupuk
    $routes->get('/transaksi', 'Transaksi::index');
    $routes->post('/transaksi/proses_penebusan', 'Transaksi::proses_penebusan');
    $routes->get('/transaksi/laporan', 'Transaksi::laporan_distribusi');
    $routes->get('/transaksi/rekap_penebusan', 'Transaksi::rekap_penebusan');
    $routes->get('/transaksi/cetak_nota/(:num)', 'Transaksi::cetak_nota/$1');
    $routes->get('/transaksi/rekap_pupuk', 'Transaksi::rekap_pupuk');

    // Laporan & Modul Keuangan Poktan
    $routes->get('/keuangan', 'Keuangan::index');
    $routes->post('/keuangan/simpan_manual', 'Keuangan::simpan_manual');
    $routes->get('/keuangan/cetak', 'Keuangan::cetak');

    // Pengelolaan Log Pasokan Pupuk Masuk
    $routes->get('/pupukmasuk', 'PupukMasuk::index');
    $routes->post('/pupukmasuk/simpan', 'PupukMasuk::simpan');
    $routes->post('/pupukmasuk/update/(:num)', 'PupukMasuk::update/$1'); 
    $routes->get('/pupukmasuk/hapus/(:num)', 'PupukMasuk::hapus/$1');   
});