<?php

namespace Config;

// Create a new instance of our RouteCollection class.
$routes = Services::routes();

/*
 * --------------------------------------------------------------------
 * Router Setup
 * --------------------------------------------------------------------
 */
$routes->setDefaultNamespace('App\Controllers');
$routes->setDefaultController('Home');
$routes->setDefaultMethod('index');
$routes->setTranslateURIDashes(false);
$routes->set404Override();
$routes->setAutoRoute(false);
// The Auto Routing (Legacy) is very dangerous. It is easy to create vulnerable apps
// where controller filters or CSRF protection are bypassed.
// If you don't want to define all routes, please use the Auto Routing (Improved).
// Set `$autoRoutesImproved` to true in `app/Config/Feature.php` and set the following to true.
// $routes->setAutoRoute(false);

/*
 * --------------------------------------------------------------------
 * Route Definitions
 * --------------------------------------------------------------------
 */

// We get a performance increase by specifying the default
// route since we don't have to scan directories.
$routes->get('/', 'Home::index');
$routes->get('/login', 'Common\AuthController::login');
$routes->post('/signin', 'Common\AuthController::signin');
$routes->get('/logout', 'Common\AuthController::logout');
$routes->group('cli', ['namespace' => 'App\Controllers\CLI\Cloudflare\API'], function ($routes) {
    $routes->cli('cloudflare/auth', 'Auth::execute');
    $routes->cli('cloudflare/account/(:any)', 'Account::execute/$1');
    $routes->cli('cloudflare/zone/record/(:any)', 'Zone::record/$1');
    $routes->cli('cloudflare/zone/firewall/(:any)', 'Zone::firewall/$1');
});
$routes->group('front', ['namespace' => 'App\Controllers\Front'], function ($routes) {
    $routes->get('/', 'FrontController::index');
});
// authGuard는 App\Config\Filters.php의 $aliases에 선언한 이름이어야 함
$routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'authFilter:master,director,cloudflare,manager'], static function ($routes) {
    $routes->get('/', 'Home::index');
    $routes->group('cloudflare/auth', ['namespace' => 'App\Controllers\Admin\Cloudflare\API', 'filter' => 'authFilter:master,director,cloudflare'], static function ($routes) {
        $routes->get('', 'AuthController::index');
        $routes->get('excel', 'AuthController::excel');
        $routes->get('insert', 'AuthController::insert_form');
        $routes->post('insert', 'AuthController::insert');
        $routes->get('update/(:num)', 'AuthController::update_form/$1');
        $routes->post('update/(:num)', 'AuthController::update/$1');
        $routes->get('view/(:num)', 'AuthController::view/$1');
        $routes->get('delete/(:num)', 'AuthController::delete/$1');
        $routes->get('toggle/(:num)/(:hash)', 'AuthController::toggle/$1/$2');
        $routes->post('batchjob', 'AuthController::batchjob', ['filter' => 'authFilter:master,director,cloudflare']);
        $routes->get('reload/(:num)', 'AuthController::reload/$1');
    });
    $routes->group('cloudflare/account', ['namespace' => 'App\Controllers\Admin\Cloudflare\API', 'filter' => 'authFilter:master,director,cloudflare'], static function ($routes) {
        $routes->get('', 'AccountController::index');
        $routes->get('excel', 'AccountController::excel');
        $routes->get('selectkey', 'AccountController::selectkey');
        $routes->get('reload/(:hash)', 'AccountController::reload/$1');
    });
    $routes->group('cloudflare/zone', ['namespace' => 'App\Controllers\Admin\Cloudflare\API'], static function ($routes) {
        $routes->get('', 'ZoneController::index');
        $routes->post('insert', 'ZoneController::insert');
        $routes->get('excel', 'ZoneController::excel');
        $routes->get('delete/(:hash)', 'ZoneController::delete/$1');
        $routes->get('toggle/(:hash)/(:any)', 'ZoneController::toggle/$1/$2');
        $routes->post('batchjob', 'ZoneController::batchjob', ['filter' => 'authFilter:master,director,cloudflare']);
        $routes->post('batchjob_delete', 'ZoneController::batchjob_delete', ['filter' => 'authFilter:master,director,cloudflare']);
        $routes->get('sync/(:hash)', 'ZoneController::sync/$1');
        $routes->get('reload/(:hash)', 'ZoneController::reload/$1');
    });
    $routes->group('cloudflare/record', ['namespace' => 'App\Controllers\Admin\Cloudflare\API'], static function ($routes) {
        $routes->get('', 'RecordController::index');
        $routes->post('insert', 'RecordController::insert');
        $routes->get('excel', 'RecordController::excel');
        $routes->get('delete/(:hash)', 'RecordController::delete/$1');
        $routes->get('toggle/(:hash)/(:hash)', 'RecordController::toggle/$1/$2');
        $routes->post('batchjob', 'RecordController::batchjob', ['filter' => 'authFilter:master,director,cloudflare']);
        $routes->get('sync/(:hash)', 'RecordController::sync/$1');
        $routes->get('cdnToggle/(:hash)', 'RecordController::cdnToggle/$1');
    });
    $routes->group('cloudflare/firewall', ['namespace' => 'App\Controllers\Admin\Cloudflare\API'], static function ($routes) {
        $routes->get('', 'FirewallController::index');
        $routes->get('excel', 'FirewallController::excel');
        $routes->get('toggle/(:hash)/(:hash)', 'FirewallController::toggle/$1/$2');
        $routes->get('sync/(:hash)', 'FirewallController::sync/$1');
        $routes->get('reload/(:hash)/(:any)', 'FirewallController::reload/$1/$2');
    });
    $routes->group('mapurl', static function ($routes) {
        $routes->get('', 'MapurlController::index');
        $routes->get('excel', 'MapurlController::excel');
        $routes->get('insert', 'MapurlController::insert_form');
        $routes->post('insert', 'MapurlController::insert');
        $routes->get('update/(:num)', 'MapurlController::update_form/$1');
        $routes->post('update/(:num)', 'MapurlController::update/$1');
        $routes->get('view/(:num)', 'MapurlController::view/$1');
        $routes->get('delete/(:num)', 'MapurlController::delete/$1');
        $routes->get('toggle/(:num)/(:hash)', 'MapurlController::toggle/$1/$2');
        $routes->post('batchjob', 'MapurlController::batchjob');
    });
    $routes->group('logger', static function ($routes) {
        $routes->get('', 'LoggerController::index');
        $routes->get('excel', 'LoggerController::excel');
        $routes->get('view/(:num)', 'LoggerController::view/$1');
        $routes->get('delete/(:num)', 'LoggerController::delete/$1', ['filter' => 'authFilter:master']);
        $routes->get('toggle/(:num)/(:hash)', 'LoggerController::toggle/$1/$2', ['filter' => 'authFilter:master,director']);
        $routes->post('batchjob', 'LoggerController::batchjob', ['filter' => 'authFilter:master']);
    });
    $routes->group('user', static function ($routes) {
        $routes->get('', 'UserController::index');
        $routes->get('excel', 'UserController::excel');
        $routes->get('insert', 'UserController::insert_form', ['filter' => 'authFilter:master,director']);
        $routes->post('insert', 'UserController::insert', ['filter' => 'authFilter:master,director']);
        $routes->get('update/(:num)', 'UserController::update_form/$1');
        $routes->post('update/(:num)', 'UserController::update/$1');
        $routes->get('view/(:num)', 'UserController::view/$1');
        $routes->get('delete/(:num)', 'UserController::delete/$1', ['filter' => 'authFilter:master,director']);
        $routes->get('toggle/(:num)/(:hash)', 'UserController::toggle/$1/$2', ['filter' => 'authFilter:master,director']);
        $routes->post('batchjob', 'UserController::batchjob', ['filter' => 'authFilter:master,director']);
    });
});
/*
 * --------------------------------------------------------------------
 * Additional Routing
 * --------------------------------------------------------------------
 *
 * There will often be times that you need additional routing and you
 * need it to be able to override any defaults in this file. Environment
 * based routes is one such time. require() additional route files here
 * to make that happen.
 *
 * You will have access to the $routes object within that file without
 * needing to reload it.
 */
if (is_file(APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php')) {
    require APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php';
}
