<?php

use CodeIgniter\Router\RouteCollection;

/**
 * @var RouteCollection $routes
 */
$routes->get('/', 'Home::index');

// Admin panel (web) - login is public, rest use adminAuth filter
$routes->get('admin/login', '\App\Controllers\Admin\Login::index');
$routes->post('admin/login/attempt', '\App\Controllers\Admin\Login::attempt');
$routes->get('admin/login/logout', '\App\Controllers\Admin\Login::logout');

$routes->get('admin', '\App\Controllers\Admin\Dashboard::index');
$routes->get('admin/orders', '\App\Controllers\Admin\Orders::index');
$routes->get('admin/orders/(:num)', '\App\Controllers\Admin\Orders::detail/$1');
$routes->post('admin/orders/(:num)/assign', '\App\Controllers\Admin\Orders::assignDriver/$1');
$routes->get('admin/rescue', '\App\Controllers\Admin\Rescue::index');
$routes->post('admin/rescue/service', '\App\Controllers\Admin\Rescue::saveService');
$routes->get('admin/users', '\App\Controllers\Admin\Users::index');
$routes->get('admin/users/(:num)', '\App\Controllers\Admin\Users::show/$1');
$routes->post('admin/users/(:num)/toggle', '\App\Controllers\Admin\Users::toggleStatus/$1');
$routes->get('admin/drivers', '\App\Controllers\Admin\Drivers::index');
$routes->post('admin/drivers/add', '\App\Controllers\Admin\Drivers::add');
$routes->get('admin/drivers/edit/(:num)', '\App\Controllers\Admin\Drivers::edit/$1');
$routes->post('admin/drivers/update/(:num)', '\App\Controllers\Admin\Drivers::update/$1');
$routes->post('admin/drivers/(:num)/toggle', '\App\Controllers\Admin\Drivers::toggleStatus/$1');
$routes->get('admin/providers', '\App\Controllers\Admin\Providers::index');
$routes->post('admin/providers/add', '\App\Controllers\Admin\Providers::addProvider');
$routes->get('admin/providers/edit/(:num)', '\App\Controllers\Admin\Providers::editProvider/$1');
$routes->post('admin/providers/edit/(:num)', '\App\Controllers\Admin\Providers::editProvider/$1');
$routes->post('admin/providers/delete/(:num)', '\App\Controllers\Admin\Providers::deleteProvider/$1');
$routes->post('admin/providers/item/add', '\App\Controllers\Admin\Providers::addItem');
$routes->post('admin/providers/item/delete/(:num)', '\App\Controllers\Admin\Providers::deleteItem/$1');
$routes->post('admin/providers/price', '\App\Controllers\Admin\Providers::savePrice');
$routes->get('admin/shop', '\App\Controllers\Admin\Shop::index');
$routes->post('admin/shop/category/add', '\App\Controllers\Admin\Shop::addCategory');
$routes->get('admin/shop/category/edit/(:num)', '\App\Controllers\Admin\Shop::editCategory/$1');
$routes->post('admin/shop/category/edit/(:num)', '\App\Controllers\Admin\Shop::editCategory/$1');
$routes->post('admin/shop/category/delete/(:num)', '\App\Controllers\Admin\Shop::deleteCategory/$1');
$routes->post('admin/shop/product/add', '\App\Controllers\Admin\Shop::addProduct');
$routes->get('admin/shop/product/edit/(:num)', '\App\Controllers\Admin\Shop::editProduct/$1');
$routes->post('admin/shop/product/edit/(:num)', '\App\Controllers\Admin\Shop::editProduct/$1');
$routes->post('admin/shop/product/delete/(:num)', '\App\Controllers\Admin\Shop::deleteProduct/$1');
$routes->get('admin/service-fee', '\App\Controllers\Admin\ServiceFee::index');
$routes->post('admin/service-fee/save', '\App\Controllers\Admin\ServiceFee::save');
$routes->get('admin/app-version', '\App\Controllers\Admin\AppVersion::index');
$routes->post('admin/app-version/save', '\App\Controllers\Admin\AppVersion::save');
$routes->get('admin/service-images', '\App\Controllers\Admin\ServiceImages::index');
$routes->post('admin/service-images/save', '\App\Controllers\Admin\ServiceImages::save');
$routes->post('admin/service-images/provider-logo', '\App\Controllers\Admin\ServiceImages::saveProviderLogo');
$routes->post('admin/service-images/inventory-image', '\App\Controllers\Admin\ServiceImages::saveInventoryImage');
$routes->get('admin/gas-kit-addons', '\App\Controllers\Admin\GasKitAddons::index');
$routes->post('admin/gas-kit-addons/add', '\App\Controllers\Admin\GasKitAddons::add');
$routes->get('admin/gas-kit-addons/edit/(:num)', '\App\Controllers\Admin\GasKitAddons::edit/$1');
$routes->post('admin/gas-kit-addons/update/(:num)', '\App\Controllers\Admin\GasKitAddons::update/$1');
$routes->post('admin/gas-kit-addons/delete/(:num)', '\App\Controllers\Admin\GasKitAddons::delete/$1');

// Shield auth routes (login, register, etc.)
$auth = service('auth');
if ($auth !== null) {
    $auth->routes($routes);
}

// FinFlo hosted checkout: callback/cancel/result are public (user's browser is redirected here)
$routes->get('api/payments/finflo/callback', '\App\Controllers\Api\FinFloController::callback');
$routes->get('api/payments/finflo/cancel', '\App\Controllers\Api\FinFloController::cancel');
$routes->get('api/payments/finflo/result', '\App\Controllers\Api\FinFloController::result');

// API routes (phone+PIN auth; Bearer token for protected routes)
$routes->group('api', ['filter' => 'apiAuth'], static function ($routes) {
    $routes->post('auth/login', '\App\Controllers\Api\AuthController::login');
    $routes->post('auth/register', '\App\Controllers\Api\AuthController::register');
    $routes->get('auth/me', '\App\Controllers\Api\AuthController::me');
    $routes->patch('auth/change-phone', '\App\Controllers\Api\AuthController::changePhone');
    $routes->patch('auth/change-pin', '\App\Controllers\Api\AuthController::changePin');
    $routes->post('auth/delete-account', '\App\Controllers\Api\AuthController::deleteAccount');

    $routes->get('config', '\App\Controllers\Api\ConfigController::index');
    $routes->get('version', '\App\Controllers\Api\VersionController::index');
    $routes->get('services', '\App\Controllers\Api\ServicesController::index');
    $routes->get('geo/check', '\App\Controllers\Api\GeoController::check');

    $routes->get('addresses', '\App\Controllers\Api\AddressesController::index');
    $routes->post('addresses', '\App\Controllers\Api\AddressesController::create');
    $routes->patch('addresses/(:num)', '\App\Controllers\Api\AddressesController::update/$1');
    $routes->delete('addresses/(:num)', '\App\Controllers\Api\AddressesController::delete/$1');

    $routes->get('providers', '\App\Controllers\Api\ProvidersController::index');
    $routes->get('gas-sizes', '\App\Controllers\Api\GasSizesController::index');
    $routes->get('gas-kit-addons', '\App\Controllers\Api\GasKitAddonsController::index');
    $routes->get('rescue-services', '\App\Controllers\Api\RescueServicesController::index');
    $routes->get('shop/categories', '\App\Controllers\Api\ShopController::categories');
    $routes->get('shop/products', '\App\Controllers\Api\ShopController::products');

    $routes->get('orders', '\App\Controllers\Api\OrdersController::index');
    $routes->get('orders/active', '\App\Controllers\Api\OrdersController::active');
    $routes->get('orders/(:num)', '\App\Controllers\Api\OrdersController::show/$1');
    $routes->post('orders', '\App\Controllers\Api\OrdersController::create');
    $routes->post('orders/complete/(:num)', '\App\Controllers\Api\OrdersController::complete/$1');

    $routes->get('notifications', '\App\Controllers\Api\NotificationsController::index');
    $routes->patch('notifications/(:num)', '\App\Controllers\Api\NotificationsController::update/$1');

    $routes->post('payments/mobile-money/request', '\App\Controllers\Api\MobileMoneyController::request');
    $routes->get('payments/mobile-money/status/(:segment)', '\App\Controllers\Api\MobileMoneyController::status/$1');

    $routes->post('payments/finflo/create-session', '\App\Controllers\Api\FinFloController::createSession');
    $routes->get('payments/finflo/status/(:segment)', '\App\Controllers\Api\FinFloController::status/$1');

    $routes->get('driver/status', '\App\Controllers\Api\DriverController::status');
    $routes->post('driver/offline', '\App\Controllers\Api\DriverController::offline');
    $routes->post('driver/location', '\App\Controllers\Api\DriverController::location');

    $routes->get('admin/drivers', '\App\Controllers\Api\AdminController::drivers');
    $routes->get('admin/suggest-drivers', '\App\Controllers\Api\AdminController::suggestDrivers');
});
