<?php

use CodeIgniter\Router\RouteCollection;

/** @var RouteCollection $routes */

$routes->setDefaultNamespace('App\Controllers');
$routes->setDefaultController('Auth');
$routes->setDefaultMethod('login');
$routes->setTranslateURIDashes(false);
$routes->set404Override();
$routes->setAutoRoute(false);

// Auth
$routes->get('/',       'Auth::login');
$routes->get('login',   'Auth::login');
$routes->post('login',  'Auth::doLogin');
$routes->get('logout',  'Auth::logout', ['filter' => 'auth']);

// Dashboard (auth required)
$routes->group('dashboard', ['filter' => 'auth'], function ($routes) {
    $routes->get('/',              'Dashboard::index');
    $routes->post('list',          'Dashboard::listData');
    $routes->get('stats',          'Dashboard::stats');
    $routes->get('field-stats',    'Dashboard::fieldStats');
    $routes->get('export',         'Dashboard::export');
    $routes->post('import',        'Dashboard::import',    ['filter' => 'admin']);
    $routes->post('delete-row',    'Dashboard::deleteRow', ['filter' => 'admin']);
    $routes->post('delete-all',    'Dashboard::deleteAll', ['filter' => 'admin']);
    $routes->post('update-row',    'Dashboard::updateRow', ['filter' => 'admin']);
});

// Links (auth required)
$routes->group('links', ['filter' => 'auth'], function ($routes) {
    $routes->get('/',              'Links::index');
    $routes->post('save',          'Links::save',          ['filter' => 'admin']);
    $routes->post('delete/(:num)', 'Links::delete/$1',     ['filter' => 'admin']);
});

// Users (admin only)
$routes->group('users', ['filter' => 'admin'], function ($routes) {
    $routes->get('/',              'Users::index');
    $routes->post('save',          'Users::save');
    $routes->post('delete/(:num)', 'Users::delete/$1');
    $routes->post('toggle/(:num)', 'Users::toggle/$1');
});

// Logs (admin only)
$routes->group('logs', ['filter' => 'admin'], function ($routes) {
    $routes->get('/',    'Logs::index');
    $routes->post('list','Logs::listData');
});

// Settings (admin only)
$routes->group('settings', ['filter' => 'admin'], function ($routes) {
    $routes->get('/',    'Settings::index');
    $routes->post('save','Settings::save');
});
