<?php

namespace App\Modules\Payroll\Models;

use App\Modules\Admin\Tenancy\Traits\BelongsToTenant;
use App\Modules\HR\Employees\Models\Employee;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class PayrollEmployeeSnapshot extends Model
{
    use BelongsToTenant;

    protected $fillable = [
        'tenant_id',
        'payroll_period_id',
        'employee_id',
        'base_salary',
        'attendance_days',
        'absent_days',
        'late_days',
        'leave_days',
        'overtime_minutes',
        'adjustments_total',
        'gross_amount',
        'snapshot_data',
        'generated_at',
    ];

    protected function casts(): array
    {
        return [
            'base_salary' => 'decimal:2',
            'leave_days' => 'decimal:2',
            'adjustments_total' => 'decimal:2',
            'gross_amount' => 'decimal:2',
            'snapshot_data' => 'array',
            'generated_at' => 'datetime',
        ];
    }

    public function period(): BelongsTo
    {
        return $this->belongsTo(PayrollPeriod::class, 'payroll_period_id');
    }

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