<?php

declare(strict_types=1);

namespace Kylin\Hr\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * 工资条模型
 *
 * 管理员工月度工资明细，包括应发工资、扣款、实发工资等。
 *
 * @property float  $total_payable 应发工资
 * @property float  $total_deduct  扣款总额
 * @property float  $net_payable   实发工资
 * @property string $month         工资月份
 */
class SalarySlip extends Model
{
    use SoftDeletes;

    protected $fillable = [
        'employee_id',
        'year',
        'month',
        'gross_salary',
        'total_deduction',
        'net_salary',
        'status',
        'generated_at',
        'confirmed_at',
    ];

    protected function casts(): array
    {
        return [
            'year' => 'integer',
            'month' => 'integer',
            'gross_salary' => 'decimal:2',
            'total_deduction' => 'decimal:2',
            'net_salary' => 'decimal:2',
            'status' => 'integer',
            'generated_at' => 'datetime',
            'confirmed_at' => 'datetime',
        ];
    }

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

    public function items(): HasMany
    {
        return $this->hasMany(SalarySlipItem::class);
    }
}
