<?php

use CodeIgniter\Router\RouteCollection;

/**
 * @var RouteCollection $routes
 */

//추가 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->get('/', 'Home::index');
$routes->group('/user', function ($routes) {
    $routes->get('login', 'UserController::login_form');
    $routes->post('login', 'UserController::login');
    $routes->get('google_login', 'UserController::google_login');
    $routes->get('logout', 'UserController::logout');
});
$routes->group('cli', ['namespace' => 'App\CLI'], function ($routes) {
    $routes->group('cloudflare', ['namespace' => 'App\CLI\Cloudflare'], function ($routes) {
        $routes->cli('reload', 'Cloudflare::reload');
    });
});
$routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'authFilter:manager'], function ($routes) {
    $routes->get('/', 'Home::index');
    $routes->group('user', function ($routes) {
        $routes->get('/', 'UserController::index');
        $routes->get('create', 'UserController::create_form', ['filter' => 'authFilter:master']);
        $routes->post('create', 'UserController::create', ['filter' => 'authFilter:master']);
        $routes->get('modify/(:num)', 'UserController::modify_form/$1');
        $routes->post('modify/(:num)', 'UserController::modify/$1');
        $routes->get('delete/(:num)', 'UserController::delete/$1', ['filter' => 'authFilter:master']);
        $routes->get('toggle/(:num)/(:any)', 'UserController::toggle/$1/$2');
        $routes->post('batchjob', 'UserController::batcjob');
        $routes->get('download/(:alpha)', 'UserController::download/$1');
    });
    $routes->group('usersns', function ($routes) {
        $routes->get('/', 'UserSNSController::index');
        $routes->get('delete/(:num)', 'UserSNSController::delete/$1', ['filter' => 'authFilter:master']);
        $routes->get('toggle/(:num)/(:any)', 'UserSNSController::toggle/$1/$2', ['filter' => 'authFilter:master']);
        $routes->post('batchjob', 'UserSNSController::batcjob', ['filter' => 'authFilter:master']);
        $routes->get('download/(:alpha)', 'UserSNSController::download/$1');
    });
    $routes->group('mapurl', function ($routes) {
        $routes->get('/', 'MapurlController::index');
        $routes->get('create', 'MapurlController::create_form');
        $routes->post('create', 'MapurlController::create');
        $routes->get('modify/(:num)', 'MapurlController::modify_form/$1');
        $routes->post('modify/(:num)', 'MapurlController::modify/$1');
        $routes->get('delete/(:num)', 'MapurlController::delete/$1');
        $routes->get('toggle/(:num)/(:any)', 'MapurlController::toggle/$1/$2');
        $routes->post('batchjob', 'MapurlController::batcjob');
        $routes->get('download/(:alpha)', 'MapurlController::download/$1');
    });
    $routes->group('cloudflare', ['namespace' => 'App\Controllers\Admin\Cloudflare', 'filter' => 'authFilter:cloudflare'], function ($routes) {
        $routes->group('auth', function ($routes) {
            $routes->get('/', 'AuthController::index');
            $routes->get('create', 'AuthController::create_form');
            $routes->post('create', 'AuthController::create');
            $routes->get('modify/(:num)', 'AuthController::modify_form/$1');
            $routes->get('delete/(:num)', 'AuthController::delete/$1', ['filter' => 'authFilter:master']);
            $routes->get('toggle/(:num)/(:any)', 'AuthController::toggle/$1/$2');
            $routes->post('batchjob', 'AuthController::batcjob');
            $routes->get('download/(:alpha)', 'AccountController::download/$1');
        });
        $routes->group('account', function ($routes) {
            $routes->get('/', 'AccountController::index');
            $routes->get('reload/(:num)', 'AccountController::reload/$1');
            $routes->get('download/(:alpha)', 'AccountController::download/$1');
        });
        $routes->group('zone', function ($routes) {
            $routes->get('/', 'ZoneController::index');
            $routes->get('create', 'ZoneController::create_form');
            $routes->post('create', 'ZoneController::create');
            $routes->get('delete/(:alphanum)', 'ZoneController::delete/$1');
            $routes->get('sync/(:alphanum)', 'ZoneController::sync/$1');
            $routes->get('toggle/(:alphanum)/(:any)', 'ZoneController::toggle/$1/$2');
            $routes->post('batchjob', 'ZoneController::batcjob');
            $routes->get('reload/(:alphanum)', 'ZoneController::reload/$1');
            $routes->get('download/(:alpha)', 'ZoneController::download/$1');
        });
        $routes->group('record', function ($routes) {
            $routes->get('/', 'RecordController::index');
            $routes->get('create', 'RecordController::create_form');
            $routes->post('create', 'RecordController::create');
            $routes->get('delete/(:alphanum)', 'RecordController::delete/$1');
            $routes->get('sync/(:alphanum)', 'RecordController::sync/$1');
            $routes->get('toggle/(:alphanum)/(:any)', 'RecordController::toggle/$1/$2');
            $routes->post('batchjob', 'RecordController::batcjob');
            $routes->get('reload/(:alphanum)', 'RecordController::reload/$1');
            $routes->get('download/(:alpha)', 'RecordController::download/$1');
        });
    });
});
