<?php

declare(strict_types=1);

namespace BotGuard\Models;

use BotGuard\Core\Model;

/**
 * Append-only audit trail of privileged actions.
 */
final class AuditLog extends Model
{
    protected string $table = 'audit_logs';

    /**
     * @param array<string, mixed> $meta
     */
    public function record(?int $userId, string $action, string $ip = '', array $meta = [], ?string $entity = null, ?string $entityId = null): void
    {
        $this->create([
            'user_id'   => $userId,
            'action'    => $action,
            'entity'    => $entity,
            'entity_id' => $entityId,
            'ip'        => $ip,
            'meta'      => json_encode($meta, JSON_UNESCAPED_SLASHES),
        ]);
    }
}
