<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

class LoanProduct extends Model
{
    use HasFactory;

    protected $fillable = [
        'code',
        'name',
        'category',
        'description',
        'min_amount',
        'max_amount',
        'interest_rate',
        'interest_method',
        'min_tenor_months',
        'max_tenor_months',
        'processing_fee_pct',
        'penalty_rate_pct',
        'requires_collateral',
        'requires_guarantor',
        'status',
    ];

    protected function casts(): array
    {
        return [
            'min_amount' => 'decimal:2',
            'max_amount' => 'decimal:2',
            'interest_rate' => 'decimal:4',
            'processing_fee_pct' => 'decimal:4',
            'penalty_rate_pct' => 'decimal:4',
            'requires_collateral' => 'boolean',
            'requires_guarantor' => 'boolean',
        ];
    }

    public function loans(): HasMany
    {
        return $this->hasMany(Loan::class, 'product_id');
    }
}
