<?php

/**
 * Transport / Fleet Management module routes.
 * @var \CodeIgniter\Router\RouteCollection $routes
 */

$routes->group('transport', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Transport\Controllers\TransportDashboardController::index', [
        'filter' => 'permission:transport.view',
    ]);
});

$routes->group('transport/vehicles', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Transport\Controllers\VehicleController::index', [
        'filter' => 'permission:transport_vehicles.view',
    ]);
    $routes->get('create', '\Modules\Transport\Controllers\VehicleController::createForm', [
        'filter' => 'permission:transport_vehicles.create',
    ]);
    $routes->post('/', '\Modules\Transport\Controllers\VehicleController::store', [
        'filter' => 'permission:transport_vehicles.create',
    ]);
    $routes->get('(:num)', '\Modules\Transport\Controllers\VehicleController::show/$1', [
        'filter' => 'permission:transport_vehicles.view',
    ]);
    $routes->get('(:num)/edit', '\Modules\Transport\Controllers\VehicleController::editForm/$1', [
        'filter' => 'permission:transport_vehicles.edit',
    ]);
    $routes->post('(:num)', '\Modules\Transport\Controllers\VehicleController::update/$1', [
        'filter' => 'permission:transport_vehicles.edit',
    ]);
    $routes->post('(:num)/delete', '\Modules\Transport\Controllers\VehicleController::destroy/$1', [
        'filter' => 'permission:transport_vehicles.delete',
    ]);
});

$routes->group('transport/drivers', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Transport\Controllers\DriverController::index', [
        'filter' => 'permission:transport_drivers.view',
    ]);
    $routes->get('create', '\Modules\Transport\Controllers\DriverController::createForm', [
        'filter' => 'permission:transport_drivers.create',
    ]);
    $routes->post('/', '\Modules\Transport\Controllers\DriverController::store', [
        'filter' => 'permission:transport_drivers.create',
    ]);
    $routes->get('(:num)', '\Modules\Transport\Controllers\DriverController::show/$1', [
        'filter' => 'permission:transport_drivers.view',
    ]);
    $routes->get('(:num)/edit', '\Modules\Transport\Controllers\DriverController::editForm/$1', [
        'filter' => 'permission:transport_drivers.edit',
    ]);
    $routes->post('(:num)', '\Modules\Transport\Controllers\DriverController::update/$1', [
        'filter' => 'permission:transport_drivers.edit',
    ]);
    $routes->post('(:num)/delete', '\Modules\Transport\Controllers\DriverController::destroy/$1', [
        'filter' => 'permission:transport_drivers.delete',
    ]);
});

$routes->group('transport/locations', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Transport\Controllers\LocationController::index', [
        'filter' => 'permission:transport_locations.view',
    ]);
    $routes->get('create', '\Modules\Transport\Controllers\LocationController::createForm', [
        'filter' => 'permission:transport_locations.create',
    ]);
    $routes->post('/', '\Modules\Transport\Controllers\LocationController::store', [
        'filter' => 'permission:transport_locations.create',
    ]);
    $routes->get('(:num)', '\Modules\Transport\Controllers\LocationController::show/$1', [
        'filter' => 'permission:transport_locations.view',
    ]);
    $routes->get('(:num)/edit', '\Modules\Transport\Controllers\LocationController::editForm/$1', [
        'filter' => 'permission:transport_locations.edit',
    ]);
    $routes->post('(:num)', '\Modules\Transport\Controllers\LocationController::update/$1', [
        'filter' => 'permission:transport_locations.edit',
    ]);
    $routes->post('(:num)/delete', '\Modules\Transport\Controllers\LocationController::destroy/$1', [
        'filter' => 'permission:transport_locations.delete',
    ]);
});

$routes->group('transport/routes', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Transport\Controllers\RouteController::index', [
        'filter' => 'permission:transport_routes.view',
    ]);
    $routes->get('create', '\Modules\Transport\Controllers\RouteController::createForm', [
        'filter' => 'permission:transport_routes.create',
    ]);
    $routes->post('/', '\Modules\Transport\Controllers\RouteController::store', [
        'filter' => 'permission:transport_routes.create',
    ]);
    $routes->get('(:num)', '\Modules\Transport\Controllers\RouteController::show/$1', [
        'filter' => 'permission:transport_routes.view',
    ]);
    $routes->get('(:num)/edit', '\Modules\Transport\Controllers\RouteController::editForm/$1', [
        'filter' => 'permission:transport_routes.edit',
    ]);
    $routes->post('(:num)', '\Modules\Transport\Controllers\RouteController::update/$1', [
        'filter' => 'permission:transport_routes.edit',
    ]);
    $routes->post('(:num)/delete', '\Modules\Transport\Controllers\RouteController::destroy/$1', [
        'filter' => 'permission:transport_routes.delete',
    ]);
});

$routes->group('transport/scheduling', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Transport\Controllers\ScheduleController::index', [
        'filter' => 'permission:transport_scheduling.view',
    ]);
    $routes->get('export', '\Modules\Transport\Controllers\DriverScheduleExportController::index', [
        'filter' => 'permission:transport_scheduling.view',
    ]);
    $routes->get('create', '\Modules\Transport\Controllers\ScheduleController::createForm', [
        'filter' => 'permission:transport_scheduling.create',
    ]);
    $routes->post('/', '\Modules\Transport\Controllers\ScheduleController::store', [
        'filter' => 'permission:transport_scheduling.create',
    ]);
    $routes->get('(:num)', '\Modules\Transport\Controllers\ScheduleController::show/$1', [
        'filter' => 'permission:transport_scheduling.view',
    ]);
    $routes->get('(:num)/edit', '\Modules\Transport\Controllers\ScheduleController::editForm/$1', [
        'filter' => 'permission:transport_scheduling.edit',
    ]);
    $routes->post('(:num)', '\Modules\Transport\Controllers\ScheduleController::update/$1', [
        'filter' => 'permission:transport_scheduling.edit',
    ]);
    $routes->post('(:num)/confirm', '\Modules\Transport\Controllers\ScheduleController::confirm/$1', [
        'filter' => 'permission:transport_scheduling.edit',
    ]);
    $routes->post('(:num)/start', '\Modules\Transport\Controllers\ScheduleController::start/$1', [
        'filter' => 'permission:transport_scheduling.edit',
    ]);
    $routes->post('(:num)/complete', '\Modules\Transport\Controllers\ScheduleController::complete/$1', [
        'filter' => 'permission:transport_scheduling.edit',
    ]);
    $routes->post('(:num)/cancel', '\Modules\Transport\Controllers\ScheduleController::cancel/$1', [
        'filter' => 'permission:transport_scheduling.edit',
    ]);
    $routes->post('(:num)/delete', '\Modules\Transport\Controllers\ScheduleController::destroy/$1', [
        'filter' => 'permission:transport_scheduling.delete',
    ]);
});

$routes->group('transport/maps', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Transport\Controllers\MapController::viewer', [
        'filter' => 'permission:transport_maps.view',
    ]);
    $routes->get('settings', '\Modules\Transport\Controllers\MapController::settingsForm', [
        'filter' => 'permission:transport_maps.edit',
    ]);
    $routes->post('settings', '\Modules\Transport\Controllers\MapController::updateSettings', [
        'filter' => 'permission:transport_maps.edit',
    ]);
});

$routes->group('transport/reports', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Transport\Controllers\TransportReportController::index', [
        'filter' => 'permission:transport_reports.view',
    ]);
});

// --- AI Planning (route optimization + scheduling assistant) ---------------

$routes->group('transport/ai/plans', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Transport\Controllers\AiPlannerController::index', [
        'filter' => 'permission:transport_ai.view',
    ]);
    $routes->get('generate', '\Modules\Transport\Controllers\AiPlannerController::generateForm', [
        'filter' => 'permission:transport_ai.generate',
    ]);
    $routes->post('/', '\Modules\Transport\Controllers\AiPlannerController::store', [
        'filter' => 'permission:transport_ai.generate',
    ]);
    $routes->get('(:num)', '\Modules\Transport\Controllers\AiPlannerController::show/$1', [
        'filter' => 'permission:transport_ai.view',
    ]);
    $routes->post('(:num)/submit', '\Modules\Transport\Controllers\AiPlannerController::submit/$1', [
        'filter' => 'permission:transport_ai.generate',
    ]);
    $routes->post('(:num)/approve', '\Modules\Transport\Controllers\AiPlannerController::approve/$1', [
        'filter' => ['permission:transport_ai.approve', 'tpin'],
    ]);
    $routes->post('(:num)/reject', '\Modules\Transport\Controllers\AiPlannerController::reject/$1', [
        'filter' => ['permission:transport_ai.approve', 'tpin'],
    ]);
    $routes->post('(:num)/delete', '\Modules\Transport\Controllers\AiPlannerController::destroy/$1', [
        'filter' => 'permission:transport_ai.generate',
    ]);
});

$routes->group('transport/ai/pickups', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Transport\Controllers\EmployeePickupController::index', [
        'filter' => 'permission:transport_ai.view',
    ]);
    $routes->get('create', '\Modules\Transport\Controllers\EmployeePickupController::createForm', [
        'filter' => 'permission:transport_ai.generate',
    ]);
    $routes->post('/', '\Modules\Transport\Controllers\EmployeePickupController::store', [
        'filter' => 'permission:transport_ai.generate',
    ]);
    $routes->get('(:num)/edit', '\Modules\Transport\Controllers\EmployeePickupController::editForm/$1', [
        'filter' => 'permission:transport_ai.generate',
    ]);
    $routes->post('(:num)', '\Modules\Transport\Controllers\EmployeePickupController::update/$1', [
        'filter' => 'permission:transport_ai.generate',
    ]);
    $routes->post('(:num)/delete', '\Modules\Transport\Controllers\EmployeePickupController::destroy/$1', [
        'filter' => 'permission:transport_ai.generate',
    ]);
});

$routes->group('transport/ai/contract-sites', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Transport\Controllers\ContractSiteController::index', [
        'filter' => 'permission:transport_ai.view',
    ]);
    $routes->get('create', '\Modules\Transport\Controllers\ContractSiteController::createForm', [
        'filter' => 'permission:transport_ai.generate',
    ]);
    $routes->post('/', '\Modules\Transport\Controllers\ContractSiteController::store', [
        'filter' => 'permission:transport_ai.generate',
    ]);
    $routes->get('(:num)/edit', '\Modules\Transport\Controllers\ContractSiteController::editForm/$1', [
        'filter' => 'permission:transport_ai.generate',
    ]);
    $routes->post('(:num)', '\Modules\Transport\Controllers\ContractSiteController::update/$1', [
        'filter' => 'permission:transport_ai.generate',
    ]);
    $routes->post('(:num)/delete', '\Modules\Transport\Controllers\ContractSiteController::destroy/$1', [
        'filter' => 'permission:transport_ai.generate',
    ]);
});

$routes->group('transport/ai/settings', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Transport\Controllers\AiSettingsController::form', [
        'filter' => 'permission:transport_ai.settings',
    ]);
    $routes->post('/', '\Modules\Transport\Controllers\AiSettingsController::update', [
        'filter' => 'permission:transport_ai.settings',
    ]);
});
