<?php

declare(strict_types=1);

namespace BotGuard\Controllers\Admin;

use BotGuard\Core\Controller;
use BotGuard\Core\Csrf;
use BotGuard\Core\Request;
use BotGuard\Core\Response;
use BotGuard\Core\Session;
use BotGuard\Core\View;
use BotGuard\Models\DetectionLog;
use BotGuard\Models\User;
use BotGuard\Models\VerificationResult;

/**
 * Administrator overview: platform-wide traffic, module health and users.
 */
final class AdminDashboardController extends Controller
{
    public function __construct(
        View $view,
        Session $session,
        Csrf $csrf,
        Request $request,
        private VerificationResult $results,
        private DetectionLog $detectionLogs,
        private User $users,
    ) {
        parent::__construct($view, $session, $csrf, $request);
    }

    public function index(Request $request): Response
    {
        return $this->render('admin.dashboard', [
            'title'         => 'Admin Overview',
            'summary'       => $this->results->summary(null),
            'trend'         => $this->results->dailyTrend(null, 30),
            'moduleHealth'  => $this->detectionLogs->moduleFailureRates(30),
            'topCountries'  => $this->results->topBy('country', null, 8),
            'userCount'     => $this->users->count(),
        ]);
    }
}
