<?php

declare(strict_types=1);

use BotGuard\Controllers\Admin\AdminDashboardController;
use BotGuard\Controllers\Admin\AnnouncementController;
use BotGuard\Controllers\Admin\BackupController;
use BotGuard\Controllers\Admin\ModuleController;
use BotGuard\Controllers\Admin\SettingsController;
use BotGuard\Controllers\Admin\ThresholdController;
use BotGuard\Controllers\User\ApiKeyController;
use BotGuard\Controllers\Auth\LoginController;
use BotGuard\Controllers\Auth\RegisterController;
use BotGuard\Controllers\User\DashboardController;
use BotGuard\Controllers\User\RedirectConfigController;
use BotGuard\Controllers\Web\HomeController;
use BotGuard\Controllers\Web\VerifyController;
use BotGuard\Core\Router;

/**
 * Web (HTML) routes.
 *
 * The file returns a closure so the Kernel can inject the shared Router. Route
 * middleware are referenced by alias: csrf, auth, admin, throttle.
 */
return static function (Router $router): void {
    // --- Public verification flow ---
    $router->get('/', HomeController::class . '@index');
    $router->get('/verify', VerifyController::class . '@show', ['throttle']);
    $router->get('/blocked', VerifyController::class . '@blocked');
    $router->get('/success', VerifyController::class . '@success');

    // --- Authentication ---
    $router->get('/login', LoginController::class . '@show');
    $router->post('/login', LoginController::class . '@login', ['csrf', 'throttle']);
    $router->post('/logout', LoginController::class . '@logout', ['csrf', 'auth']);
    $router->get('/register', RegisterController::class . '@show');
    $router->post('/register', RegisterController::class . '@register', ['csrf', 'throttle']);

    // --- User dashboard ---
    $router->group(['prefix' => '/dashboard', 'middleware' => ['auth']], static function (Router $r): void {
        $r->get('', DashboardController::class . '@index');
        $r->get('/logs', DashboardController::class . '@logs');
        $r->get('/reports', DashboardController::class . '@reports');
        $r->get('/analytics', DashboardController::class . '@analytics');
        $r->get('/export/csv', DashboardController::class . '@exportCsv');
        $r->get('/export/xlsx', DashboardController::class . '@exportXlsx');
        $r->get('/export/pdf', DashboardController::class . '@exportPdf');
        $r->get('/redirects', RedirectConfigController::class . '@edit');
        $r->post('/redirects', RedirectConfigController::class . '@update', ['csrf']);
        $r->get('/api-keys', ApiKeyController::class . '@index');
        $r->post('/api-keys', ApiKeyController::class . '@create', ['csrf']);
        $r->post('/api-keys/revoke', ApiKeyController::class . '@revoke', ['csrf']);
    });

    // --- Admin panel ---
    $router->group(['prefix' => '/admin', 'middleware' => ['auth', 'admin']], static function (Router $r): void {
        $r->get('', AdminDashboardController::class . '@index');
        $r->get('/modules', ModuleController::class . '@index');
        $r->post('/modules', ModuleController::class . '@update', ['csrf']);
        $r->get('/thresholds', ThresholdController::class . '@index');
        $r->post('/thresholds', ThresholdController::class . '@update', ['csrf']);
        $r->get('/smtp', SettingsController::class . '@smtp');
        $r->post('/smtp', SettingsController::class . '@update', ['csrf']);
        $r->post('/smtp/test', SettingsController::class . '@test', ['csrf']);
        $r->get('/announcements', AnnouncementController::class . '@index');
        $r->post('/announcements', AnnouncementController::class . '@create', ['csrf']);
        $r->post('/announcements/toggle', AnnouncementController::class . '@toggle', ['csrf']);
        $r->post('/announcements/delete', AnnouncementController::class . '@delete', ['csrf']);
        $r->get('/backups', BackupController::class . '@index');
        $r->post('/backups', BackupController::class . '@create', ['csrf']);
        $r->get('/backups/download', BackupController::class . '@download');
        $r->post('/backups/delete', BackupController::class . '@delete', ['csrf']);
    });
};
