<?php

use CodeIgniter\Router\RouteCollection;

/**
 * @var RouteCollection $routes
 */
$routes->get('/', 'Landing::index');
$routes->get('lang/(:segment)', 'Landing::setLanguage/$1');
$routes->get('audit', 'Audit::index');
$routes->get('verify', 'Audit::index');
$routes->get('demo/meter', 'Demo::meter');
$routes->post('demo/meter/communicate', 'Demo::communicate');
$routes->get('login', 'Auth::login');
$routes->post('login', 'Auth::authenticate');
$routes->get('register', 'Auth::register');
$routes->post('register', 'Auth::storeRegistration');
$routes->get('logout', 'Auth::logout', ['filter' => 'auth']);
$routes->get('account', 'Auth::account', ['filter' => 'auth']);
$routes->post('account', 'Auth::updateAccount', ['filter' => 'auth']);
$routes->get('organizations/switch/(:num)', 'Auth::switchOrganization/$1', ['filter' => 'auth']);

$routes->group('', ['filter' => 'auth'], static function ($routes) {
    $routes->get('dashboard', 'Dashboard::index');
    $routes->get('analytics', 'Analytics::index');
    $routes->get('api-keys', 'ApiKeys::index');
    $routes->post('api-keys', 'ApiKeys::create');
    $routes->post('api-keys/(:num)/revoke', 'ApiKeys::revoke/$1');
    $routes->get('api-docs', 'ApiDocs::index');
    $routes->get('api-playground', 'ApiPlayground::index');
    $routes->get('privacy-settings', 'PrivacySettings::index');
    $routes->post('privacy-settings', 'PrivacySettings::update');

    $routes->get('organizations', 'Organizations::index');
    $routes->get('organizations/new', 'Organizations::new');
    $routes->post('organizations', 'Organizations::create');
    $routes->get('organizations/(:num)/edit', 'Organizations::edit/$1');
    $routes->post('organizations/(:num)', 'Organizations::update/$1');
    $routes->post('organizations/(:num)/delete', 'Organizations::delete/$1');

    $routes->get('sites', 'Sites::index');
    $routes->get('sites/new', 'Sites::new');
    $routes->post('sites', 'Sites::create');
    $routes->get('sites/(:num)/edit', 'Sites::edit/$1');
    $routes->post('sites/(:num)', 'Sites::update/$1');
    $routes->post('sites/(:num)/delete', 'Sites::delete/$1');

    $routes->get('turbines', 'Turbines::index');
    $routes->get('turbines/new', 'Turbines::new');
    $routes->post('turbines', 'Turbines::create');
    $routes->get('turbines/(:num)/edit', 'Turbines::edit/$1');
    $routes->post('turbines/(:num)', 'Turbines::update/$1');
    $routes->post('turbines/(:num)/delete', 'Turbines::delete/$1');

    $routes->get('maintenance', 'Maintenance::index');
    $routes->get('maintenance/new', 'Maintenance::new');
    $routes->post('maintenance', 'Maintenance::create');
    $routes->get('maintenance/(:segment)/edit', 'Maintenance::edit/$1');
    $routes->post('maintenance/(:segment)/anchor-blockchain', 'Maintenance::anchorBlockchain/$1');
    $routes->post('maintenance/(:segment)', 'Maintenance::update/$1');
    $routes->post('maintenance/(:segment)/delete', 'Maintenance::delete/$1');
    $routes->get('maintenance/(:segment)', 'Maintenance::show/$1');

    $routes->get('blockchain', 'Blockchain::index');
    $routes->get('team', 'Team::index');
    $routes->get('team/new', 'Team::new');
    $routes->post('team', 'Team::create');
    $routes->get('team/(:num)/edit', 'Team::edit/$1');
    $routes->post('team/(:num)', 'Team::update/$1');
    $routes->post('team/(:num)/delete', 'Team::delete/$1');

    // Legacy aliases while the remaining module names are still being migrated.
    $routes->get('facilities', 'Sites::index');
    $routes->get('facilities/new', 'Sites::new');
    $routes->post('facilities', 'Sites::create');
    $routes->get('facilities/(:num)/edit', 'Sites::edit/$1');
    $routes->post('facilities/(:num)', 'Sites::update/$1');
    $routes->post('facilities/(:num)/delete', 'Sites::delete/$1');

    $routes->get('meters', 'Turbines::index');
    $routes->get('meters/new', 'Turbines::new');
    $routes->post('meters', 'Turbines::create');
    $routes->get('meters/(:num)/edit', 'Turbines::edit/$1');
    $routes->post('meters/(:num)', 'Turbines::update/$1');
    $routes->post('meters/(:num)/delete', 'Turbines::delete/$1');

    $routes->get('certificates', 'Maintenance::index');
    $routes->get('certificates/new', 'Maintenance::new');
    $routes->post('certificates', 'Maintenance::create');
    $routes->get('certificates/(:segment)', 'Maintenance::show/$1');
});

$routes->group('api/v1', ['filter' => 'cors'], static function ($routes) {
    $routes->get('audit', 'Api\Audit::index');
    $routes->get('sites', 'Api\Sites::index');
    $routes->post('sites', 'Api\Sites::create');
    $routes->get('turbines', 'Api\Turbines::index');
    $routes->post('turbines', 'Api\Turbines::create');
    $routes->get('maintenance', 'Api\Maintenance::index');
    $routes->post('maintenance/preview', 'Api\Maintenance::preview');
    $routes->post('maintenance', 'Api\Maintenance::create');
    $routes->get('maintenance/(:segment)', 'Api\Maintenance::show/$1');
    $routes->get('blockchain', 'Api\Blockchain::index');

    // Legacy API aliases while consumers migrate to Quantum naming.
    $routes->get('verify', 'Api\Audit::index');
    $routes->get('facilities', 'Api\Sites::index');
    $routes->post('facilities', 'Api\Sites::create');
    $routes->get('meters', 'Api\Turbines::index');
    $routes->post('meters', 'Api\Turbines::create');
    $routes->get('certificates', 'Api\Maintenance::index');
    $routes->post('certificates/preview', 'Api\Maintenance::preview');
    $routes->post('certificates', 'Api\Maintenance::create');
    $routes->get('certificates/(:segment)', 'Api\Maintenance::show/$1');
});
