<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class LoanTransaction extends Model
{
    protected $fillable = [
        'loan_id',
        'payroll_id',
        'source',
        'note',
        'recorded_by',
        'deducted_amount',
        'remaining_after',
    ];

    protected function casts(): array
    {
        return [
            'deducted_amount' => 'decimal:2',
            'remaining_after' => 'decimal:2',
        ];
    }

    public function loan()
    {
        return $this->belongsTo(Loan::class);
    }

    public function payroll()
    {
        return $this->belongsTo(Payroll::class);
    }

    public function recorder()
    {
        return $this->belongsTo(User::class, 'recorded_by');
    }
}
