<?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 int    $from_department_id 原部门ID
 * @property int    $to_department_id   新部门ID
 * @property int    $from_position_id   原职位ID
 * @property int    $to_position_id     新职位ID
 * @property string $status             审批状态
 */
class EmployeeTransfer extends Model
{
    use SoftDeletes;

    protected $fillable = [
        'employee_id',
        'from_department_id',
        'to_department_id',
        'from_position_id',
        'to_position_id',
        'effective_date',
        'reason',
        'approval_status',
    ];

    protected function casts(): array
    {
        return [
            'effective_date' => 'date',
            'approval_status' => ApprovalStatus::class,
        ];
    }

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

    public function fromDepartment(): BelongsTo
    {
        return $this->belongsTo(Department::class, 'from_department_id');
    }

    public function toDepartment(): BelongsTo
    {
        return $this->belongsTo(Department::class, 'to_department_id');
    }

    public function fromPosition(): BelongsTo
    {
        return $this->belongsTo(Position::class, 'from_position_id');
    }

    public function toPosition(): BelongsTo
    {
        return $this->belongsTo(Position::class, 'to_position_id');
    }
}
