<?php

use CodeIgniter\Router\RouteCollection;

/**
 * @var RouteCollection $routes
 */
// Rute Login (Tidak difilter)
$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->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');

$routes->post('/auth/register', 'Auth::register');
$routes->get('/auth/reset_admin', 'Auth::reset_admin');

// GRUP RUTE TERPROTEKSI (Wajib Login)
$routes->group('', ['filter' => 'auth'], function ($routes) {
    $routes->get('/', 'Home::index');
    $routes->get('/dashboard', 'Home::index');

    // Petani & Pupuk
    $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');

    $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');

    // Alokasi, Transaksi, Keuangan
    $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/cetak', 'Alokasi::cetak');

    $routes->get('/transaksi', 'Transaksi::index');
    $routes->post('/transaksi/proses', 'Transaksi::proses_penebusan');
    $routes->get('/transaksi/laporan', 'Transaksi::laporan_distribusi');

    $routes->get('/keuangan', 'Keuangan::index');
    $routes->post('/keuangan/simpan_manual', 'Keuangan::simpan_manual');

    $routes->get('/keuangan', 'Keuangan::index');
    $routes->post('/keuangan/simpan_manual', 'Keuangan::simpan_manual');
    // Tambahkan ini:
    $routes->get('/keuangan/cetak', 'Keuangan::cetak');
});
