<?php

namespace App\Modules\HR\Payroll\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use App\Modules\HR\Core\Models\Employee;
use App\Modules\HR\Payroll\Models\PayrollProcess;
use App\Modules\HR\Payroll\Models\EmployeeLoan;

class PayrollProcessLoan extends Model
{
    use HasFactory;

    protected $table = 'payroll_process_loans';

    protected $fillable = [
        'payroll_process_id',
        'employee_id',
        'employee_loan_id',
        'amount',
        'remarks',
    ];

    protected $casts = [
        'amount' => 'decimal:2',
    ];

    /* ================= Relationships ================= */

    public function payrollProcess(): BelongsTo
    {
        return $this->belongsTo(PayrollProcess::class, 'payroll_process_id');
    }

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

    public function employeeLoan(): BelongsTo
    {
        return $this->belongsTo(EmployeeLoan::class, 'employee_loan_id');
    }
}
