<?php

namespace App\Models;

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

class Student extends Model
{
  use HasFactory;

  protected $fillable = [
    'studentId',
    'firstName',
    'lastName',
    'dateOfBirth',
    'gender',
    'email',
    'address',
  ];

  public function schedules()
  {
    return $this->belongsToMany(
      'App\Models\Schedule',
      'schedule_student_rel',
      'student_id', // foreign key name of the model on which you are defining the relationship
      'schedule_id'
    ); // foreign key name of the model that you are joining to
  }

  public function noticesRead()
  {
    return $this->belongsToMany(
      'App\Models\Notice',
      'notice_student_rel',
      'student_id', // foreign key name of the model on which you are defining the relationship
      'notice_id'
    ); // foreign key name of the model that you are joining to
  }

  public function notices()
  {
    return $this->belongsToMany(
      'App\Models\Notice',
      'notice_student_rel',
      'student_id', // foreign key name of the model on which you are defining the relationship
      'notice_id'
    ); // foreign key name of the model that you are joining to
  }

  public function presentSchedule()
  {
    // action to preform when student attend a schedule

    return $this->belongsToMany(
      'App\Models\Schedule',
      'present_schedule_rel',
      'student_id', // foreign key name of the model on which you are defining the relationship
      'schedule_id'
    ); // foreign key name of the model that you are joining to
  }

  public function exams()
  {
    return $this->belongsToMany(
      'App\Models\Exam',
      'exam_student_rel',
      'student_id',
      'exam_id'
    );
  }

  // public function exam_results()
  // {
  //     return $this->belongsToMany(
  //         'App\Models\ExamResult',
  //         'exam_exam_result_rel',
  //         'exam_result_id',
  //         'student_id');
  // }

  public function exam_results()
  {
    return $this->hasMany('App\Models\ExamResult');
  }
}
