<?php

namespace App\Models;

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

class StudentRegister extends Model
{
    use HasFactory;
    protected $table = 'student_registrations';
    protected $fillable = [
        'student_id',
        'first_name',
        'last_name',
        'teacher_id',
        'class_id',
        'teacher_class_id',
        'upn',
        'email',
    ];
    
    protected $casts = [
        'student_id' => 'integer',
        'teacher_id' => 'integer',
        'teacher_class_id' => 'integer',
        'class_id' => 'integer',
    ];

    // Relationship with StudentClass
    public function studentClasses()
    {
        return $this->hasMany(StudentClass::class, 'student_register_id');
    }

    public function studentClass()
    {
        return $this->hasOne(StudentClass::class, 'student_register_id', 'id');
    }

    // Other relationships (if required)
    public function classRelation()
    {
        return $this->belongsTo(Classes::class, 'class_id')->withTrashed();
    }

    public function teacher()
    {
        return $this->belongsTo(Teacher::class, 'teacher_id');
    }

    public function student()
    {
        return $this->belongsTo(Student::class, 'student_id');
    }

    // Relationship with StudentQuiz
    public function quizzes()
    {
        return $this->hasMany(StudentQuiz::class, 'student_id', 'id');
    }
}
