<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Question extends Model
{
    /**
     * fillable
     *
     * @var array
     */
    protected $fillable = [
        'lesson_id',
        'type',
        'difficulty',
        'kompetensi',
        'question',
        'image',
        'option_1',
        'option_1_image',
        'option_2',
        'option_2_image',
        'option_3',
        'option_3_image',
        'option_4',
        'option_4_image',
        'option_5',
        'option_5_image',
        'answer',
    ];

    /**
     * The attributes that should be cast.
     *
     * @var array<string, string>
     */
    protected $casts = [
        'answer' => 'array',
    ];

    /**
     * exams
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function exams()
    {
        return $this->belongsToMany(Exam::class, 'exam_questions')->withPivot('order_number');
    }

    /**
     * lesson
     */
    public function lesson()
    {
        return $this->belongsTo(Lesson::class);
    }

}
