<?php
namespace App\Models;
use App\Models\Scopes\ParentBranchScope;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class CustomerDocument extends Model
{
    protected $fillable = ['customer_id','document_type','original_name','file_path','mime_type','file_size','expiry_date','notes','uploaded_by'];
    protected function casts(): array { return ['expiry_date'=>'date']; }
    protected static function booted(): void
    {
        static::addGlobalScope(new ParentBranchScope('customers', 'customer_id', 'id', ['document']));
    }
    public function customer(): BelongsTo { return $this->belongsTo(Customer::class); }
    public function uploader(): BelongsTo { return $this->belongsTo(User::class, 'uploaded_by'); }
}
