<?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;
use Kylin\Hr\Enums\LeaveType;

/**
 * 请假申请模型
 *
 * 管理员工请假申请，包括请假类型、时间、审批状态等。
 *
 * @property string $leave_type 请假类型
 * @property string $start_date 开始日期
 * @property string $end_date   结束日期
 * @property string $reason     请假原因
 * @property string $status     审批状态
 */
class LeaveRequest extends Model
{
    use SoftDeletes;

    protected $fillable = [
        'employee_id',
        'type',
        'start_time',
        'end_time',
        'duration',
        'reason',
        'approval_status',
        'approver_id',
        'approval_opinion',
        'approved_at',
    ];

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

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

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