<?php

use CodeIgniter\Router\RouteCollection;

/**
 * @var RouteCollection $routes
 */
// $routes->get('/', 'Home::index');


//choi.jh
//추가 Custom RULE 만들때 : ex)UUID형식
$routes->addPlaceholder('uuid', '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}');
//authFilter는 추가적인 작업이 필요
//1. app/Filters/AuthFilter.php
//2. Config/Filters.php -> $aliases = ['authFilter' => AuthFilter::class]
$routes->group('cli', ['namespace' => 'App\Controllers\CLI'], function ($routes) {
});

$routes->group('', ['namespace' => 'App\Controllers'], function ($routes) {
    $routes->get('/', 'Welcome::index');
    $routes->group('auth', ['namespace' => 'App\Controllers\Auth'], function ($routes) {
        $routes->get('login', 'LocalController::login_form');
        $routes->post('login', 'LocalController::login');
        $routes->get('google_login', 'GoogleController::login');
        $routes->get('logout', 'LocalController::logout');
    });
});
//Admin 관련
$routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'authFilter:manager'], function ($routes) {
    $routes->get('/', 'Welcome::index');
    $routes->group('user', function ($routes) {
        $routes->get('/', 'UserController::index');
        $routes->get('create', 'UserController::create_form');
        $routes->post('create', 'UserController::create');
        $routes->get('modify/(:num)', 'UserController::modify_form/$1');
        $routes->post('modify/(:num)', 'UserController::modify/$1');
        $routes->get('view/(:num)', 'UserController::view/$1');
        $routes->get('delete/(:num)', 'UserController::delete/$1', ['filter' => 'authFilter:master']);
        $routes->get('toggle/(:num)/(:any)', 'UserController::toggle/$1/$2', ['filter' => 'authFilter:master']);
        $routes->post('batchjob', 'UserController::batchjob', ['filter' => 'authFilter:master']);
        $routes->post('batchjob_delete', 'UserController::batchjob_delete', ['filter' => 'authFilter:master']);
        $routes->get('download/(:alpha)', 'UserController::download/$1');
    });
    $routes->group('search', function ($routes) {
        $routes->get('/', 'SearchController::index');
    });
    $routes->group('board', function ($routes) {
        $routes->get('/', 'BoardController::index');
        $routes->get('create', 'BoardController::create_form');
        $routes->post('create', 'BoardController::create');
        $routes->get('modify/(:num)', 'BoardController::modify_form/$1');
        $routes->post('modify/(:num)', 'BoardController::modify/$1');
        $routes->get('view/(:num)', 'BoardController::view/$1');
        $routes->get('delete/(:num)', 'BoardController::delete/$1');
        $routes->get('toggle/(:num)/(:any)', 'BoardController::toggle/$1/$2');
        $routes->post('batchjob', 'BoardController::batchjob');
        $routes->post('batchjob_delete', 'BoardController::batchjob_delete');
        $routes->get('download/(:alpha)', 'BoardController::download/$1');
        $routes->get('latest/(:alpha)', 'BoardController::latest/$1');
    });
});
//choi.jh