<?php

namespace App\Models;

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

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

    protected static function booted(): void
    {
        static::addGlobalScope(new ParentBranchScope('collaterals', 'collateral_id', 'id', ['file']));
    }

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

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