<?php

namespace App\Models;

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

class LoanEarlySettlement extends Model
{
    protected $fillable = [
        'settlement_number','loan_id','customer_id','branch_id','financial_account_id','principal_amount','interest_amount',
        'fees_amount','penalties_amount','settlement_adjustment','final_amount','adjustment_reason','settlement_date','reference',
        'notes','settled_by','financial_account_transaction_id',
    ];

    protected function casts(): array
    {
        return [
            'principal_amount'=>'decimal:2','interest_amount'=>'decimal:2','fees_amount'=>'decimal:2','penalties_amount'=>'decimal:2',
            'settlement_adjustment'=>'decimal:2','final_amount'=>'decimal:2','settlement_date'=>'date',
        ];
    }

    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 settler(): BelongsTo { return $this->belongsTo(User::class, 'settled_by'); }
    public function accountTransaction(): BelongsTo { return $this->belongsTo(FinancialAccountTransaction::class, 'financial_account_transaction_id'); }
}
