<?php

namespace App\Models;

use App\Models\Concerns\BelongsToBranch;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class StudentAttendance extends Model
{
    use BelongsToBranch;

    protected $fillable = [
        'branch_id', 'student_id', 'class_id', 'section_id',
        'date', 'status', 'remarks', 'marked_by',
    ];

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

    public const STATUSES = ['present', 'absent', 'leave', 'late', 'half_day'];

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

    public static function statusColor(string $status): string
    {
        return [
            'present' => 'success', 'absent' => 'danger', 'leave' => 'info',
            'late' => 'warning', 'half_day' => 'secondary',
        ][$status] ?? 'secondary';
    }
}
