<?php

namespace App\Models;

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

class LoanWriteOffRecovery extends Model
{
    protected $fillable = [
        'recovery_number','loan_write_off_id','loan_id','customer_id','branch_id','financial_account_id',
        'financial_account_transaction_id','amount','recovery_date','method','reference','notes','received_by',
    ];

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

    public function writeOff(): BelongsTo { return $this->belongsTo(LoanWriteOff::class, 'loan_write_off_id'); }
    public function loan(): BelongsTo { return $this->belongsTo(Loan::class); }
    public function customer(): BelongsTo { return $this->belongsTo(Customer::class); }
    public function branch(): BelongsTo { return $this->belongsTo(Branch::class); }
    public function financialAccount(): BelongsTo { return $this->belongsTo(FinancialAccount::class); }
    public function accountTransaction(): BelongsTo { return $this->belongsTo(FinancialAccountTransaction::class, 'financial_account_transaction_id'); }
    public function receiver(): BelongsTo { return $this->belongsTo(User::class, 'received_by'); }
}
