<?php

declare(strict_types=1);

namespace App\Controllers;

use App\Helpers\Response;
use App\Services\DashboardService;

class DashboardController extends BaseController
{
    private DashboardService $dashboardService;

    public function __construct($request)
    {
        parent::__construct($request);
        $this->dashboardService = new DashboardService();
    }

    public function index(): void
    {
        $filterEventId = $this->request->query('event_id');
        if ($filterEventId !== null) {
            $filterEventId = (int) $filterEventId;
        }

        $kpis = $this->dashboardService->getKPIs(
            $this->getAuthUserId(),
            $this->getAuthUserRole(),
            $this->getAuthUserEventId(),
            $filterEventId
        );

        Response::success($kpis, 'Dashboard consultado correctamente');
    }
}
