<?php

namespace App\Models;

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

class PegawaiValidationHistory extends Model
{
    use HasFactory;

    protected $fillable = [
        'pegawai_id',
        'admin_id',
        'status_sebelumnya',
        'status_baru',
        'catatan',
    ];

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

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

    public function getStatusSebelumnyaLabelAttribute(): string
    {
        return $this->statusLabel($this->status_sebelumnya);
    }

    public function getStatusBaruLabelAttribute(): string
    {
        return $this->statusLabel($this->status_baru);
    }

    private function statusLabel(?string $status): string
    {
        return match ($status) {
            'pending' => 'Menunggu Validasi',
            'disetujui' => 'Disetujui',
            'ditolak' => 'Ditolak',
            null => '-',
            default => 'Tidak Diketahui',
        };
    }
}
