<?php

namespace App\Modules\HR\Employees\Models;

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

class EmployeeEmploymentHistory extends Model
{
    use BelongsToTenant;

    protected $fillable = [
        'tenant_id', 'employee_id', 'type', 'effective_date', 'previous_value',
        'new_value', 'reason', 'notes', 'meta', 'created_by',
    ];

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

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

    public function createdBy(): BelongsTo
    {
        return $this->belongsTo(User::class, 'created_by');
    }
}
