<?php

declare(strict_types=1);

namespace Kylin\Hr\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Kylin\Hr\Enums\ApprovalStatus;

/**
 * 加班申请模型
 *
 * 管理员工加班申请，包括加班时间、原因、审批状态等。
 *
 * @property string $start_time 开始时间
 * @property string $end_time   结束时间
 * @property float  $hours      加班时长
 * @property string $reason     加班原因
 * @property string $status     审批状态
 */
class OvertimeRequest extends Model
{
    use SoftDeletes;

    protected $fillable = [
        'employee_id',
        'date',
        'start_time',
        'end_time',
        'duration',
        'reason',
        'approval_status',
        'approver_id',
        'compensatory_type',
    ];

    protected function casts(): array
    {
        return [
            'date' => 'date',
            'start_time' => 'datetime',
            'end_time' => 'datetime',
            'duration' => 'decimal:1',
            'approval_status' => ApprovalStatus::class,
        ];
    }

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

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