<?php

namespace App\Models;

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

class LoanPenaltyCharge extends Model
{
    protected $fillable = [
        'loan_id', 'loan_installment_id', 'branch_id', 'effective_date', 'period_key',
        'penalty_type', 'penalty_value', 'base_amount', 'amount', 'days_overdue', 'source',
        'penalty_reason', 'settlement_mode',
    ];

    protected function casts(): array
    {
        return [
            'effective_date' => 'date',
            'penalty_value' => 'decimal:6',
            'base_amount' => 'decimal:2',
            'amount' => 'decimal:2',
            'days_overdue' => 'integer',
        ];
    }

    public function loan(): BelongsTo { return $this->belongsTo(Loan::class); }
    public function installment(): BelongsTo { return $this->belongsTo(LoanInstallment::class, 'loan_installment_id'); }
    public function branch(): BelongsTo { return $this->belongsTo(Branch::class); }
}
