<?php

namespace App\Models;

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

class WarningLetter extends Model
{
    use HasFactory;

    protected $fillable = [
        'user_id',
        'letter_type',
        'letter_number',
        'alpha_count',
        'month',
        'issued_date',
        'notes',
        'created_by',
    ];

    protected function casts(): array
    {
        return [
            'issued_date' => 'date',
        ];
    }

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

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

    public function getLetterTypeLabelAttribute(): string
    {
        return match ($this->letter_type) {
            'sp1' => 'Surat Peringatan 1 (SP1)',
            'sp2' => 'Surat Peringatan 2 (SP2)',
            'panggilan_ortu' => 'Surat Panggilan Orang Tua',
            default => strtoupper($this->letter_type),
        };
    }
}
