<?php

namespace App\Models;

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

class StudentSelfQuizAnswerPart extends Model
{
    use HasFactory;
    protected $table = 'student_self_quiz_answer_parts';
    protected $fillable = [
        'quiz_self_answer_id',
        'question_id',
        'question_part_id',
        'answer',
        'outcome',
        'score',
        'obtainMarks',
        'totalMarks',
        'reason',
    ];
    
    protected $casts = [
        'quiz_self_answer_id' => 'integer',
        'question_id' => 'integer',
        'question_part_id' => 'integer',
        'outcome' => 'integer',
        'obtainMarks' => 'integer',
        'totalMarks' => 'integer',
    ];

    public function studentQuizAnswer()
    {
        return $this->belongsTo(StudentSelfQuizAnswser::class, 'quiz_self_answer_id', 'id');
    }

    // Relationship with QuizTopicQuestion
    public function question()
    {
        return $this->belongsTo(TopicQuestion::class, 'question_id', 'id');
    }

    public function questionPart()
    {
        return $this->belongsTo(TopicQuestionPart::class, 'question_part_id', 'id');
    }

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

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

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