<?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.

//추가 RULE UUID형식
$routes->addPlaceholder('uuid', '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}');

$routes->get('/', 'Home::index');
$routes->get('/login', 'AuthController::login');
$routes->post('/signin', 'AuthController::signin/local');
$routes->get('/signin/(:alpha)', 'AuthController::signin/$1');
$routes->get('/logout', 'AuthController::logout');
$routes->group('cli', ['namespace' => 'App\Controllers\CLI'], function ($routes) {
});
$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('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/(:uuid)', 'UserController::update_form/$1');
        $routes->post('update/(:uuid)', 'UserController::update/$1');
        $routes->get('view/(:uuid)', 'UserController::view/$1');
        $routes->get('delete/(:uuid)', 'UserController::delete/$1', ['filter' => 'authFilter:master,director']);
        $routes->get('toggle/(:uuid)/(:hash)', 'UserController::toggle/$1/$2', ['filter' => 'authFilter:master,director']);
        $routes->post('batchjob', 'UserController::batchjob', ['filter' => 'authFilter:master,director']);
    });
    $routes->group('usersns', static function ($routes) {
        $routes->get('', 'UserSNSController::index');
        $routes->get('excel', 'UserSNSController::excel');
        $routes->get('view/(:num)', 'UserSNSController::view/$1');
        $routes->get('delete/(:num)', 'UserSNSController::delete/$1', ['filter' => 'authFilter:master,director']);
        $routes->get('toggle/(:num)/(:hash)', 'UserSNSController::toggle/$1/$2', ['filter' => 'authFilter:master,director']);
    });
    $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']);
    });
});
/*
 * --------------------------------------------------------------------
 * 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';
}
