<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Schedule extends Model
{
  use HasFactory;

  protected $fillable = ['subject', 'startTime', 'endTime', 'description'];

  public function teachers()
  {
    return $this->belongsToMany('App\Models\Teacher', 'schedule_teacher_rel');
  }

  public function students()
  {
    return $this->belongsToMany('App\Models\Student', 'schedule_student_rel');
  }

  public function subjects()
  {
    return $this->belongsToMany('App\Models\Subject', 'schedule_subject_rel');
  }

  public function classrooms()
  {
    return $this->belongsToMany(
      'App\Models\ClassRoom',
      'class_room_activities'
    )->withPivot(['id', 'date_epoch']);
  }

  public function presentStudent()
  {
    return $this->belongsToMany(
      'App\Models\Student',
      'present_schedule_rel',
      'schedule_id',
      'student_id'
    );
  }
}
