<?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('/signup', 'AuthController::signup/local');
$routes->get('/signup/(:alpha)', 'AuthController::signup/$1');
$routes->get('/logout', 'AuthController::logout');
$routes->group('ecommerce', ['namespace' => 'App\Controllers'], static function ($routes) {
    $routes->post('addCart', 'EcommerceController::addCart');
    $routes->get('cancelCart/(:uuid)', 'EcommerceController::cancelCart/$1');
});;
$routes->group('cli', ['namespace' => 'App\Controllers\CLI'], function ($routes) {
});
// 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');
        $routes->post('insert', 'UserController::insert');
        $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']);
        $routes->get('toggle/(:uuid)/(:hash)', 'UserController::toggle/$1/$2');
        $routes->post('batchjob', 'UserController::batchjob');
    });
    $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');
        $routes->get('toggle/(:num)/(:hash)', 'UserSNSController::toggle/$1/$2');
        $routes->post('batchjob', 'UserSNSController::batchjob');
    });
    $routes->group('boardconfig', static function ($routes) {
        $routes->get('', 'BoardConfigController::index');
        $routes->get('excel', 'BoardConfigController::excel/$1');
        $routes->get('insert', 'BoardConfigController::insert_form');
        $routes->post('insert', 'BoardConfigController::insert');
        $routes->get('update/(:uuid)', 'BoardConfigController::update_form/$1');
        $routes->post('update/(:uuid)', 'BoardConfigController::update/$1');
        $routes->get('view/(:uuid)', 'BoardConfigController::view/$1');
        $routes->get('delete/(:uuid)', 'BoardConfigController::delete/$1', ['filter' => 'authFilter:master']);
        $routes->get('toggle/(:uuid)/(:hash)', 'BoardConfigController::toggle/$1/$2');
        $routes->post('batchjob', 'BoardConfigController::batchjob');
    });
    $routes->group('board', static function ($routes) {
        $routes->get('', 'BoardController::index');
        $routes->get('excel', 'BoardController::excel/$1');
        $routes->get('insert', 'BoardController::insert_form');
        $routes->post('insert', 'BoardController::insert');
        $routes->get('update/(:num)', 'BoardController::update_form/$1');
        $routes->post('update/(:num)', 'BoardController::update/$1');
        $routes->get('view/(:num)', 'BoardController::view/$1');
        $routes->get('reply/(:num)', 'BoardController::reply_form/$1');
        $routes->post('reply/(:num)', 'BoardController::reply/$1');
        $routes->get('delete/(:num)', 'BoardController::delete/$1', ['filter' => 'authFilter:master']);
        $routes->get('toggle/(:num)/(:hash)', 'BoardController::toggle/$1/$2');
        $routes->post('batchjob', 'BoardController::batchjob');
        $routes->get('download/(:any)/(:num)', 'BoardController::download/$1/$2');
    });
    $routes->group('category', static function ($routes) {
        $routes->get('', 'CategoryController::index');
        $routes->get('excel', 'CategoryController::excel/$1');
        $routes->get('insert', 'CategoryController::insert_form');
        $routes->post('insert', 'CategoryController::insert');
        $routes->get('update/(:num)', 'CategoryController::update_form/$1');
        $routes->post('update/(:num)', 'CategoryController::update/$1');
        $routes->get('view/(:num)', 'CategoryController::view/$1');
        $routes->get('reply/(:num)', 'CategoryController::reply_form/$1');
        $routes->post('reply/(:num)', 'CategoryController::reply/$1');
        $routes->get('delete/(:num)', 'CategoryController::delete/$1', ['filter' => 'authFilter:master']);
        $routes->get('toggle/(:num)/(:hash)', 'CategoryController::toggle/$1/$2');
        $routes->post('batchjob', 'CategoryController::batchjob');
    });
    $routes->group('product', static function ($routes) {
        $routes->get('', 'ProductController::index');
        $routes->get('excel', 'ProductController::excel/$1');
        $routes->get('insert', 'ProductController::insert_form');
        $routes->post('insert', 'ProductController::insert');
        $routes->get('update/(:uuid)', 'ProductController::update_form/$1');
        $routes->post('update/(:uuid)', 'ProductController::update/$1');
        $routes->get('view/(:uuid)', 'ProductController::view/$1');
        $routes->get('delete/(:uuid)', 'ProductController::delete/$1', ['filter' => 'authFilter:master']);
        $routes->get('toggle/(:uuid)/(:hash)', 'ProductController::toggle/$1/$2');
        $routes->post('batchjob', 'ProductController::batchjob');
        $routes->get('download/(:any)/(:uuid)', 'ProductController::download/$1/$2');
    });
    $routes->group('order', static function ($routes) {
        $routes->get('', 'OrderController::index');
        $routes->get('view/(:uuid)', 'OrderController::view/$1');
        $routes->get('delete/(:uuid)', 'OrderController::delete/$1', ['filter' => 'authFilter:master']);
        $routes->get('toggle/(:uuid)/(:hash)', 'OrderController::toggle/$1/$2');
        $routes->post('batchjob', 'OrderController::batchjob`');
    });
});
$routes->group('front', ['namespace' => 'App\Controllers\Front'], function ($routes) {
    $routes->group('user', ['namespace' => 'App\Controllers\Front', 'filter' => 'authFilter:master,director,cloudflare,manager,gold,silver,brone,vip,user'], static function ($routes) {
        $routes->get('update', 'UserController::update_form');
        $routes->post('update', 'UserController::update');
        $routes->get('view', 'UserController::view');
    });
    $routes->group('board', static function ($routes) {
        $routes->get('', 'BoardController::index');
        $routes->get('excel', 'BoardController::excel/$1');
        $routes->get('insert', 'BoardController::insert_form');
        $routes->post('insert', 'BoardController::insert');
        $routes->get('update/(:num)', 'BoardController::update_form/$1');
        $routes->post('update/(:num)', 'BoardController::update/$1');
        $routes->get('view/(:num)', 'BoardController::view/$1');
        $routes->get('reply/(:num)', 'BoardController::reply_form/$1');
        $routes->post('reply/(:num)', 'BoardController::reply/$1');
        $routes->get('delete/(:num)', 'BoardController::delete/$1', ['filter' => 'authFilter:master']);
        $routes->get('download/(:any)/(:num)', 'BoardController::download/$1/$2');
    });
    $routes->group('product', static function ($routes) {
        $routes->get('', 'ProductController::index');
        $routes->get('excel', 'ProductController::excel/$1');
        $routes->get('view/(:uuid)', 'ProductController::view/$1');
    });
    $routes->group('order', static function ($routes) {
        $routes->get('', 'OrderController::index');
        $routes->get('view/(:uuid)', 'OrderController::view/$1');
    });;
});
/*
 * --------------------------------------------------------------------
 * 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';
}
