<?php

namespace App\Models;

use App\Enum\Esign\EsignEventType;
use App\Enum\Esign\EsignStatus;
use App\Trait\BelongsToSolicitor;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
 * One immutable audit row per Fintrixor webhook event, attached to an EsignDocument.
 */
class EsignEvent extends Model
{
    use BelongsToSolicitor;

    protected $table = 'esign_events';

    protected $fillable = [
        'esign_document_id',
        'solicitor_id',
        'event_type',
        'mapped_status',
        'provider_event_id',
        'payload',
        'occurred_at',
    ];

    protected $casts = [
        'event_type' => EsignEventType::class,
        'mapped_status' => EsignStatus::class,
        'payload' => 'array',
        'occurred_at' => 'datetime',
    ];

    public function esignDocument(): BelongsTo
    {
        return $this->belongsTo(EsignDocument::class);
    }
}
