<?php

declare(strict_types=1);

namespace App\Controllers;

use App\Helpers\Response;
use App\Services\AuditService;

class AuditController extends BaseController
{
    private AuditService $auditService;

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

    public function index(): void
    {
        $filters = [
            'user_id' => $this->request->query('user_id'),
            'action' => $this->request->query('action'),
            'entity_type' => $this->request->query('entity_type'),
        ];
        $page = (int) ($this->request->query('page', 1));
        $perPage = (int) ($this->request->query('per_page', 30));

        $result = $this->auditService->getLogs($filters, $page, $perPage);

        Response::paginated($result['items'], $result['total'], $result['page'], $result['per_page'], 'Auditoría consultada correctamente');
    }
}
