<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class ApplicationDocument extends Model
{
    protected $table = 'application_documents';

    protected $fillable = [
        'application_id',
        'document_type',
        'name',
        'file_url',
        'size',
        'uploaded_by',
        'verified_at',
        'verified_by',
        'notes',
    ];

    protected $casts = [
        'size' => 'integer',
        'verified_at' => 'datetime',
    ];

    public function application()
    {
        return $this->belongsTo(FinancingApplication::class, 'application_id');
    }

    public function uploader(): BelongsTo
    {
        return $this->belongsTo(User::class, 'uploaded_by');
    }

    public function verifier(): BelongsTo
    {
        return $this->belongsTo(User::class, 'verified_by');
    }

    public function isVerified(): bool
    {
        return $this->verified_at !== null;
    }
}