<?php

namespace App\Models;

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

class FinancialTransfer extends Model
{
    protected $fillable = ['transfer_number','source_account_id','destination_account_id','amount','transfer_date','reference','notes','created_by'];

    protected function casts(): array
    {
        return ['amount'=>'decimal:2','transfer_date'=>'date'];
    }

    protected static function booted(): void
    {
        static::addGlobalScope(new FinancialTransferScope());
    }

    public function sourceAccount(): BelongsTo { return $this->belongsTo(FinancialAccount::class, 'source_account_id'); }
    public function destinationAccount(): BelongsTo { return $this->belongsTo(FinancialAccount::class, 'destination_account_id'); }
    public function creator(): BelongsTo { return $this->belongsTo(User::class, 'created_by'); }
}
