<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Relations\BelongsTo;

class PayrollItem extends BaseModel
{
    protected $fillable = [
        'payroll_id',
        'employee_id',
        'gross_salary',
        'total_earnings',
        'total_deductions',
        'tax_deduction',
        'loan_deduction',
        'addition_adjustment',
        'deduction_adjustment',
        'net_salary',
        'salary_breakdown',
    ];

    protected function casts(): array
    {
        return [
            'salary_breakdown' => 'array',
            'gross_salary' => 'decimal:2',
            'total_earnings' => 'decimal:2',
            'total_deductions' => 'decimal:2',
            'tax_deduction' => 'decimal:2',
            'loan_deduction' => 'decimal:2',
            'addition_adjustment' => 'decimal:2',
            'deduction_adjustment' => 'decimal:2',
            'net_salary' => 'decimal:2',
        ];
    }

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

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