<?php

declare(strict_types=1);

namespace ImovelZapAi\Signatures\Infrastructure\Persistence\Eloquent;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use ImovelZapAi\Shared\Infrastructure\Persistence\Concerns\BelongsToTenant;
use ImovelZapAi\Shared\Infrastructure\Persistence\Concerns\HasUuidPrimaryKey;
use ImovelZapAi\Signatures\Domain\Enums\SignatureAuditEvent;

class SignatureAuditModel extends Model
{
    use BelongsToTenant;
    use HasUuidPrimaryKey;

    public $timestamps = false;

    protected $table = 'signature_audits';

    protected $fillable = [
        'tenant_id', 'signature_request_id', 'event', 'actor_type',
        'actor_user_id', 'signer_id', 'payload', 'message', 'created_at',
    ];

    protected function casts(): array
    {
        return [
            'event' => SignatureAuditEvent::class,
            'payload' => 'array',
            'created_at' => 'datetime',
        ];
    }

    public function request(): BelongsTo
    {
        return $this->belongsTo(SignatureRequestModel::class, 'signature_request_id');
    }

    public function signer(): BelongsTo
    {
        return $this->belongsTo(SignerModel::class, 'signer_id');
    }
}
