<?php
declare(strict_types=1);

namespace App\Controllers;

use App\Core\Controller;
use App\Core\Response;
use App\Models\AuditLogModel;

/**
 * Audit Log Controller
 */
class AuditController extends Controller
{
    private AuditLogModel $auditLogModel;

    public function __construct()
    {
        $this->auditLogModel = new AuditLogModel();
    }

    public function index(): void
    {
        $tenantId = (int) $_REQUEST['tenant_id'];
        $filters = [
            'module' => $_GET['module'] ?? null,
            'action' => $_GET['action'] ?? null
        ];
        $page = (int) ($_GET['page'] ?? 1);
        $perPage = (int) ($_GET['per_page'] ?? 20);

        $logs = $this->auditLogModel->getAll($tenantId, $filters, $page, $perPage);
        $total = $this->auditLogModel->countAll($tenantId, $filters);

        Response::paginated($logs, $total, $page, $perPage);
    }
}
