<?php

use CodeIgniter\Router\RouteCollection;
use App\Filters\AuthFilter;

/**
 * @var RouteCollection $routes
 */
$routes->get('login', 'Auth\AuthController::login');
$routes->post('login', 'Auth\AuthController::processLogin');
$routes->get('logout', 'Auth\AuthController::logout');

$routes->get('/', 'PageController::dashboard', ['filter' => AuthFilter::class]);

$routes->get('/master/dept', 'PageController::masterDept', ['filter' => AuthFilter::class]);
$routes->get('/master/test', 'PageController::masterTest', ['filter' => AuthFilter::class]);
$routes->get('/master/control', 'PageController::masterControl', ['filter' => AuthFilter::class]);
$routes->get('/master/control-tests', 'PageController::controlTests', ['filter' => AuthFilter::class]);
$routes->get('/dept', 'PageController::dept', ['filter' => AuthFilter::class]);
$routes->get('/test', 'PageController::test', ['filter' => AuthFilter::class]);
$routes->get('/control', 'PageController::control', ['filter' => AuthFilter::class]);
$routes->get('/entry', 'PageController::entry', ['filter' => AuthFilter::class]);
$routes->get('/entry/daily', 'PageController::entryDaily', ['filter' => AuthFilter::class]);
$routes->get('/entry/monthly', 'PageController::entryMonthly', ['filter' => AuthFilter::class]);
$routes->get('/report', 'PageController::report', ['filter' => AuthFilter::class]);
$routes->get('/report/merged', 'PageController::reportMerged', ['filter' => AuthFilter::class]);

$routes->group('api', ['filter' => AuthFilter::class], function ($routes) {
    $routes->get('dashboard/recent', 'Api\DashboardApiController::getRecent');
    $routes->get('dept', 'Api\DeptApiController::index');
    $routes->get('dept/(:num)', 'Api\DeptApiController::show/$1');
    $routes->post('dept', 'Api\DeptApiController::store');
    $routes->patch('dept/(:num)', 'Api\DeptApiController::update/$1');
    $routes->delete('dept/(:num)', 'Api\DeptApiController::delete/$1');

    $routes->get('test', 'Api\TestApiController::index');
    $routes->get('test/(:num)', 'Api\TestApiController::show/$1');
    $routes->post('test', 'Api\TestApiController::create');
    $routes->patch('test/(:num)', 'Api\TestApiController::update/$1');
    $routes->delete('test/(:num)', 'Api\TestApiController::delete/$1');

    $routes->get('control', 'Api\ControlApiController::index');
    $routes->get('control/(:num)', 'Api\ControlApiController::show/$1');
    $routes->get('control/(:num)/tests', 'Api\ControlApiController::getTests/$1');
    $routes->post('control', 'Api\ControlApiController::create');
    $routes->patch('control/(:num)', 'Api\ControlApiController::update/$1');
    $routes->delete('control/(:num)', 'Api\ControlApiController::delete/$1');

    $routes->get('entry/controls', 'Api\EntryApiController::getControls');
    $routes->get('entry/tests', 'Api\EntryApiController::getTests');
    $routes->get('entry/daily', 'Api\EntryApiController::getDailyData');
    $routes->get('entry/monthly', 'Api\EntryApiController::getMonthlyData');
    $routes->post('entry/daily', 'Api\EntryApiController::saveDaily');
    $routes->post('entry/monthly', 'Api\EntryApiController::saveMonthly');
    $routes->post('entry/comment', 'Api\EntryApiController::saveComment');
});

    $routes->group('api/master', ['filter' => AuthFilter::class], function ($routes) {
    $routes->get('depts', 'Master\MasterDeptsController::index');
    $routes->get('depts/(:num)', 'Master\MasterDeptsController::show/$1');
    $routes->post('depts', 'Master\MasterDeptsController::create');
    $routes->patch('depts/(:num)', 'Master\MasterDeptsController::update/$1');
    $routes->delete('depts/(:num)', 'Master\MasterDeptsController::delete/$1');

    $routes->get('controls', 'Master\MasterControlsController::index');
    $routes->get('controls/(:num)', 'Master\MasterControlsController::show/$1');
    $routes->post('controls', 'Master\MasterControlsController::create');
    $routes->patch('controls/(:num)', 'Master\MasterControlsController::update/$1');
    $routes->delete('controls/(:num)', 'Master\MasterControlsController::delete/$1');

    $routes->get('tests', 'Master\MasterTestsController::index');
    $routes->get('tests/(:num)', 'Master\MasterTestsController::show/$1');
    $routes->post('tests', 'Master\MasterTestsController::create');
    $routes->patch('tests/(:num)', 'Master\MasterTestsController::update/$1');
    $routes->delete('tests/(:num)', 'Master\MasterTestsController::delete/$1');
});

$routes->group('api/qc', ['filter' => AuthFilter::class], function ($routes) {
    $routes->get('control-tests', 'Qc\ControlTestsController::index');
    $routes->get('control-tests/(:num)', 'Qc\ControlTestsController::show/$1');
    $routes->post('control-tests', 'Qc\ControlTestsController::create');
    $routes->patch('control-tests/(:num)', 'Qc\ControlTestsController::update/$1');
    $routes->delete('control-tests/(:num)', 'Qc\ControlTestsController::delete/$1');

    $routes->get('results', 'Qc\ResultsController::index');
    $routes->get('results/(:num)', 'Qc\ResultsController::show/$1');
    $routes->post('results', 'Qc\ResultsController::create');
    $routes->patch('results/(:num)', 'Qc\ResultsController::update/$1');
    $routes->delete('results/(:num)', 'Qc\ResultsController::delete/$1');

    $routes->get('test-comments', 'Qc\TestCommentsController::index');
    $routes->get('test-comments/(:num)', 'Qc\TestCommentsController::show/$1');
    $routes->post('test-comments', 'Qc\TestCommentsController::create');
    $routes->patch('test-comments/(:num)', 'Qc\TestCommentsController::update/$1');
    $routes->delete('test-comments/(:num)', 'Qc\TestCommentsController::delete/$1');
});
