<?php

namespace App\Models;

use App\Models\Scopes\ParentBranchScope;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class LoanDocument extends Model
{
    protected $fillable = ['loan_id','kind','document_type','original_name','file_path','mime_type','file_size','notes','uploaded_by'];

    protected static function booted(): void
    {
        static::addGlobalScope(new ParentBranchScope('loans', 'loan_id', 'id', ['document']));
    }

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