<?php

namespace Config;

use CodeIgniter\Router\RouteCollection;

// 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('/', 'Front\Home::index');
$routes->group('cli', ['namespace' => 'App\Controllers\CLI'], function ($routes) {
});
// authGuard는 App\Config\Filters.php의 $aliases에 선언한 이름이어야 함
$routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'authFilter: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', ['filter' => 'authFilter:master']);
        $routes->post('batchjob', 'UserController::batchjob', ['filter' => 'authFilter:master']);
    });
    $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']);
        $routes->get('toggle/(:num)/(:hash)', 'UserSNSController::toggle/$1/$2', ['filter' => 'authFilter:master']);
        $routes->post('batchjob', 'UserSNSController::batchjob', ['filter' => 'authFilter:master']);
    });
    $routes->group('category', static function ($routes) {
        $routes->get('', 'CategoryController::index');
        $routes->get('excel', 'CategoryController::excel');
        $routes->get('insert', 'CategoryController::insert_form');
        $routes->post('insert', 'CategoryController::insert');
        $routes->get('update/(:alpha)', 'CategoryController::update_form/$1');
        $routes->post('update/(:alpha)', 'CategoryController::update/$1');
        $routes->get('reply/(:alpha)', 'CategoryController::reply_form/$1');
        $routes->post('reply/(:alpha)', 'CategoryController::reply/$1');
        $routes->get('view/(:alpha)', 'CategoryController::view/$1');
        $routes->get('delete/(:alpha)', 'CategoryController::delete/$1', ['filter' => 'authFilter:master']);
        $routes->get('toggle/(:alpha)/(:hash)', 'CategoryController::toggle/$1/$2');
        $routes->post('batchjob', 'CategoryController::batchjob');
    });
    $routes->group('board', static function ($routes) {
        $routes->get('', 'BoardController::index');
        $routes->get('excel', 'BoardController::excel');
        $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('sitepage', static function ($routes) {
        $routes->get('', 'SitepageController::index');
        $routes->get('excel', 'SitepageController::excel');
        $routes->get('insert', 'SitepageController::insert_form');
        $routes->post('insert', 'SitepageController::insert');
        $routes->get('update/(:num)', 'SitepageController::update_form/$1');
        $routes->post('update/(:num)', 'SitepageController::update/$1');
        $routes->get('view/(:num)', 'SitepageController::view/$1');
        $routes->get('delete/(:num)', 'SitepageController::delete/$1', ['filter' => 'authFilter:master']);
        $routes->get('toggle/(:num)/(:hash)', 'SitepageController::toggle/$1/$2');
        $routes->post('batchjob', 'SitepageController::batchjob');
    });
    $routes->group('device', static function ($routes) {
        $routes->get('', 'DeviceController::index');
        $routes->get('excel', 'DeviceController::excel');
        $routes->get('insert', 'DeviceController::insert_form');
        $routes->post('insert', 'DeviceController::insert');
        $routes->get('update/(:uuid)', 'DeviceController::update_form/$1');
        $routes->post('update/(:uuid)', 'DeviceController::update/$1');
        $routes->get('view/(:uuid)', 'DeviceController::view/$1');
        $routes->get('delete/(:uuid)', 'DeviceController::delete/$1', ['filter' => 'authFilter:master']);
        $routes->get('toggle/(:uuid)/(:hash)', 'DeviceController::toggle/$1/$2');
        $routes->post('batchjob', 'DeviceController::batchjob');
    });
    $routes->group('product', static function ($routes) {
        $routes->get('', 'ProductController::index');
        $routes->get('excel', 'ProductController::excel');
        $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('excel', 'OrderController::excel');
        $routes->get('update/(:uuid)', 'OrderController::update_form/$1');
        $routes->post('update/(:uuid)', 'OrderController::update/$1');
        $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('billing', static function ($routes) {
        $routes->get('', 'BillingController::index');
        $routes->get('excel', 'BillingController::excel');
        $routes->get('update/(:num)', 'BillingController::update_form/$1');
        $routes->post('update/(:num)', 'BillingController::update/$1');
        $routes->get('view/(:num)', 'BillingController::view/$1');
        $routes->get('delete/(:num)', 'BillingController::delete/$1', ['filter' => 'authFilter:master']);
        $routes->get('toggle/(:num)/(:hash)', 'BillingController::toggle/$1/$2');
        $routes->post('batchjob', 'BillingController::batchjob`');
        $routes->get('download/(:any)/(:num)', 'BillingController::download/$1/$2');
    });
});
$routes->group('front', ['namespace' => 'App\Controllers\Front'], function ($routes) {
    $routes->group('user', static function ($routes) {
        $routes->get('', 'UserController::index', ['filter' => 'authFilter:user']);
        $routes->get('insert', 'UserController::insert_form');
        $routes->post('insert', 'UserController::insert');
        $routes->get('update/(:uuid)', 'UserController::update_form/$1', ['filter' => 'authFilter:user']);
        $routes->post('update/(:uuid)', 'UserController::update/$1', ['filter' => 'authFilter:user']);
        $routes->get('login', 'UserController::login_form');
        $routes->post('login', 'UserController::login/local');
        $routes->get('signup/(:alpha)', 'UserController::login/$1');
        $routes->get('logout', 'UserController::logout', ['filter' => 'authFilter:user']);
    });
    $routes->group('board', static function ($routes) {
        $routes->get('', 'BoardController::index');
        $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');
        $routes->get('download/(:any)/(:num)', 'BoardController::download/$1/$2');
    });
    $routes->group('sitepage', static function ($routes) {
        $routes->get('', 'SitepageController::index');
    });
    $routes->group('product', static function ($routes) {
        $routes->get('', 'ProductController::index');
        $routes->get('view/(:uuid)', 'ProductController::view/$1');
    });
    $routes->group('order', static function ($routes) {
        $routes->get('', 'OrderController::index');
        $routes->get('excel', 'OrderController::excel');
        $routes->get('update/(:uuid)', 'OrderController::update_form/$1');
        $routes->post('update/(:uuid)', 'OrderController::update/$1');
        $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('billing', ['namespace' => 'App\Controllers\Front\Billing', 'filter' => 'authFilter:user'], static function ($routes) {
        $routes->get('', 'BillingController::index');
        $routes->post('', 'BillingController::insert');
        $routes->get('view/(:num)', 'BillingController::view/$1');
        $routes->get('card/(:num)', 'CardController::update_form/$1');
        $routes->post('card/(:num)', 'CardController::update/$1');
        $routes->get('deposit/(:num)', 'DepositController::update_form/$1');
        $routes->post('deposit/(:num)', 'DepositController::update/$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';
}
