<?php

namespace App\Models\ESign;

use App\Traits\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class EsignAuditLog extends Model
{
    use BelongsToTenant;

    protected $table = 'esign_audit_logs';

    public $timestamps = false;

    // 액션 상수
    public const ACTION_CREATED = 'created';
    public const ACTION_SENT = 'sent';
    public const ACTION_VIEWED = 'viewed';
    public const ACTION_OTP_SENT = 'otp_sent';
    public const ACTION_AUTHENTICATED = 'authenticated';
    public const ACTION_SIGNED = 'signed';
    public const ACTION_REJECTED = 'rejected';
    public const ACTION_COMPLETED = 'completed';
    public const ACTION_CANCELLED = 'cancelled';
    public const ACTION_REMINDED = 'reminded';
    public const ACTION_DOWNLOADED = 'downloaded';

    protected $fillable = [
        'tenant_id',
        'contract_id',
        'signer_id',
        'action',
        'ip_address',
        'user_agent',
        'metadata',
        'created_at',
    ];

    protected $casts = [
        'metadata' => 'array',
        'created_at' => 'datetime',
    ];

    // === Relations ===

    public function contract(): BelongsTo
    {
        return $this->belongsTo(EsignContract::class, 'contract_id');
    }

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