<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;

class LoanEntry extends BaseModel
{
    use HasFactory;

    protected $fillable = [
        'loan_provider_id',
        'loan_type_id',
        'principal_amount',
        'interest_rate',
        'duration_type',
        'duration',
        'total_payable',
        'monthly_payable',
        'start_date',
        'end_date',
        'status',
        'notes',
        'location_id',
        'apply_on_cash',
    ];

    protected $casts = [
        'apply_on_cash' => 'boolean',
    ];

    public function provider()
    {
        return $this->belongsTo(LoanProvider::class, 'loan_provider_id');
    }

    public function type()
    {
        return $this->belongsTo(LoanType::class, 'loan_type_id');
    }

    public function repayments()
    {
        return $this->hasMany(LoanRepayment::class);
    }
}
