<?php

declare(strict_types=1);

namespace ImovelZapAi\Signatures\Application\Services;

use ImovelZapAi\Signatures\Domain\Enums\SignatureAuditEvent;
use ImovelZapAi\Signatures\Infrastructure\Persistence\Eloquent\SignatureAuditModel;

final class SignatureAuditWriter
{
    /** @param  array<string, mixed>|null  $payload */
    public function write(
        string $tenantId,
        string $requestId,
        SignatureAuditEvent $event,
        string $actorType = 'system',
        ?int $actorUserId = null,
        ?string $signerId = null,
        ?array $payload = null,
        ?string $message = null,
    ): void {
        SignatureAuditModel::query()->create([
            'tenant_id' => $tenantId,
            'signature_request_id' => $requestId,
            'event' => $event,
            'actor_type' => $actorType,
            'actor_user_id' => $actorUserId,
            'signer_id' => $signerId,
            'payload' => $payload,
            'message' => $message,
            'created_at' => now(),
        ]);
    }
}
