<?php

declare(strict_types=1);

namespace Kylin\Education\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
 * 学生班级关联
 */
class StudentClass extends Model
{
    protected $table = 'student_classes';

    protected $fillable = [
        'name',
        'course_id',
        'teacher_id',
        'capacity',
        'status',
    ];

    protected $casts = [
        'capacity' => 'integer',
        'status' => 'boolean',
    ];

    /**
     * 关联学员
     */
    public function students(): BelongsToMany
    {
        return $this->belongsToMany(Student::class, 'student_class_pivot', 'class_id', 'student_id');
    }

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

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