<?php

namespace App\Models;

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

class LoanDisbursement extends Model
{
    protected $fillable = [
        'disbursement_number','loan_id','branch_id','financial_account_id','amount','disbursement_date',
        'reference','notes','disbursed_by','financial_account_transaction_id',
    ];

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

    public function loan(): BelongsTo { return $this->belongsTo(Loan::class); }
    public function branch(): BelongsTo { return $this->belongsTo(Branch::class); }
    public function financialAccount(): BelongsTo { return $this->belongsTo(FinancialAccount::class); }
    public function user(): BelongsTo { return $this->belongsTo(User::class, 'disbursed_by'); }
    public function accountTransaction(): BelongsTo { return $this->belongsTo(FinancialAccountTransaction::class, 'financial_account_transaction_id'); }
}
