<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Batch extends Model
{
    protected $fillable = [
        'name',
        'start_date',
        'status',
        'schedules',
    ];

    protected $casts = [
        'start_date' => 'date',
        'schedules'  => 'array',
    ];

    public function getBadgeClassAttribute(): string
    {
        return match($this->status) {
            'Running'   => 'badge-green',
            'Upcoming'  => 'badge-amber',
            'Completed' => 'badge-slate',
            default     => 'badge-slate',
        };
    }

    public function students()
    {
        return $this->hasMany(\App\Models\Student::class);
    }

    public function courses()
    {
        return $this->hasManyThrough(
            \App\Models\Course::class,
            \App\Models\Student::class,
            'batch_id',
            'id',
            'id',
            'course_id'
        );
    }
}
