<?php

namespace App\Models;

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

class Loan extends Model
{
    use HasFactory;

    protected $fillable = [
        'employee_id',
        'amount',
        'term_months',
        'monthly_installment',
        'reason',
        'status',
        'manager_id',
        'applied_at',
        'approved_at',
        'start_date',
        'end_date',
        'remaining_balance',
        'remaining_months',
    ];

    protected $casts = [
        'amount' => 'decimal:2',
        'monthly_installment' => 'decimal:2',
        'applied_at' => 'datetime',
        'approved_at' => 'datetime',
        'start_date' => 'date',
        'end_date' => 'date',
        'remaining_balance' => 'decimal:2',
    ];

    public function employee()
    {
        return $this->belongsTo(Employee::class);
    }

    public function manager()
    {
        return $this->belongsTo(Employee::class, 'manager_id');
    }
}
