<?php

namespace App\Models;

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

class StudentQuiz extends Model
{
    use HasFactory;
    protected $table = 'student_quizzes';
    protected $fillable = [
        'student_id',
        'teacher_id',
        'teacher_class_id',
        'quiz_id',
        'score',
        'obtain_marks',
        'total_marks',
        'outcome',
        'start_time',
        'end_time',
        'total_time',
        'percentage',
        'total_count'
    ];
    
    protected $casts = [
        'student_id' => 'integer',
        'teacher_id' => 'integer',
        'teacher_class_id' => 'integer',
        'quiz_id' => 'integer',
        'outcome' => 'integer',
        'percentage' => 'integer',
        'total_count' => 'integer',
    ];

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

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

    public function teacherClass()
    {
        return $this->belongsTo(TeacherClass::class, 'teacher_class_id', 'id');
    }

    public function answers()
    {
        return $this->hasMany(StudentQuizAnswer::class, 'student_quiz_id', 'id');
    }

    public function quiz()
    {
        return $this->belongsTo(Quiz::class);
    }
}
