<?php

declare(strict_types=1);

namespace Kylin\Education\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Kylin\Education\Enums\ScheduleStatus;

/**
 * 课表安排
 */
class Schedule extends Model
{
    protected $table = 'schedules';

    protected $fillable = [
        'course_id',
        'teacher_id',
        'classroom_id',
        'day_of_week',
        'start_time',
        'end_time',
        'effective_date',
        'expiry_date',
        'status',
    ];

    protected $casts = [
        'day_of_week' => 'integer',
        'start_time' => 'datetime:H:i',
        'end_time' => 'datetime:H:i',
        'effective_date' => 'date',
        'expiry_date' => 'date',
        'status' => ScheduleStatus::class,
    ];

    /**
     * 关联课程
     */
    public function course(): BelongsTo
    {
        return $this->belongsTo(Course::class, 'course_id');
    }

    /**
     * 关联教师
     */
    public function teacher(): BelongsTo
    {
        return $this->belongsTo(config('auth.providers.users.model', \App\Models\User::class), 'teacher_id');
    }

    /**
     * 关联教室
     */
    public function classroom(): BelongsTo
    {
        return $this->belongsTo(Classroom::class, 'classroom_id');
    }
}
