<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class PegawaiJabatanHistory extends Model
{
    use HasFactory;

    protected $fillable = [
        'pegawai_id',
        'jabatan_fungsional_id',
        'nama_jabatan',
        'jenjang',
        'golongan',
        'tanggal_mulai_jabatan',
        'jabatan_sebelumnya',
        'jenjang_sebelumnya',
        'jabatan_saat_ini',
        'jenjang_saat_ini',
        'sk_file_id',
        'nomor_sk',
        'status',
        'admin_id',
        'catatan',
    ];

    protected $casts = [
        'tanggal_mulai_jabatan' => 'date',
    ];

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

    public function jabatan(): BelongsTo
    {
        return $this->belongsTo(JabatanFungsional::class, 'jabatan_fungsional_id');
    }

    public function skFile(): BelongsTo
    {
        return $this->belongsTo(PegawaiFile::class, 'sk_file_id');
    }

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

    public function getStatusLabelAttribute(): string
    {
        return match ($this->status) {
            'aktif' => 'Aktif',
            'selesai' => 'Selesai',
            default => 'Tidak Diketahui',
        };
    }
}
