<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class StaffLoan extends Model
{
    use SoftDeletes;

    protected $fillable = [
        'loan_number', 'employee_id', 'company_id', 'approved_by',
        'principal_amount', 'outstanding_balance', 'interest_rate',
        'term_months', 'purpose', 'deduction_type', 'deduction_value',
        'status', 'notes', 'start_date', 'payment_method', 'bank_account_id',
    ];

    protected $casts = [
        'principal_amount'   => 'decimal:2',
        'outstanding_balance'=> 'decimal:2',
        'interest_rate'      => 'decimal:2',
        'deduction_value'    => 'decimal:2',
        'start_date'         => 'date',
    ];

    public function employee()    { return $this->belongsTo(Employee::class); }
    public function company()     { return $this->belongsTo(Company::class); }
    public function approvedBy()  { return $this->belongsTo(User::class, 'approved_by'); }
    public function deductions()  { return $this->hasMany(StaffLoanDeduction::class); }
    public function bankAccount() { return $this->belongsTo(BankAccount::class); }
}
