<?php

namespace App\Models;

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

class QuizUnit extends Model
{
    use HasFactory, SoftDeletes;
    protected $table = 'quiz_units';
    protected $fillable = [
        'quiz_id', 'quiz_subject_id', 'unit_id'
    ];
    
    protected $casts = [
        'quiz_id' => 'integer',
        'quiz_subject_id' => 'integer',
        'unit_id' => 'integer',
    ];

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

    public function topics()
    {
        return $this->hasMany(QuizTopic::class, 'quiz_unit_id', 'id');
    }

    public function unit()
    {
        return $this->belongsTo(Unit::class, 'unit_id');
    }
}
