<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class StudentAttendance extends Model
{
    protected $fillable = [
        'student_id',
        'date',
        'status',
        'notes',
        'recorded_by',
    ];

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

    public function student()
    {
        return $this->belongsTo(Student::class);
    }

    public function recorder()
    {
        return $this->belongsTo(Teacher::class, 'recorded_by');
    }

    // Label status untuk tampil di view
    public static function statusLabel(string $status): string
    {
        return match ($status) {
            'hadir' => 'Hadir',
            'sakit' => 'Sakit',
            'izin'  => 'Izin',
            'alfa'  => 'Alfa',
            default => $status,
        };
    }

    public static function statusColor(string $status): string
    {
        return match ($status) {
            'hadir' => 'success',
            'sakit' => 'warning',
            'izin'  => 'info',
            'alfa'  => 'danger',
            default => 'secondary',
        };
    }
}
