<?php

declare(strict_types=1);

namespace Kylin\Education\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Kylin\Education\Enums\QuestionDifficulty;
use Kylin\Education\Enums\QuestionType;

/**
 * 题目模型
 *
 * 考试题目，支持单选、多选、判断、填空、简答等多种题型。
 *
 * @property int              $id
 * @property QuestionType     $type       题型
 * @property string           $content    题目内容
 * @property array            $options    选项（JSON）
 * @property QuestionDifficulty $difficulty 难度
 */
class Question extends Model
{
    protected $table = 'questions';

    protected $fillable = [
        'course_id',
        'type',
        'content',
        'options',
        'answer',
        'analysis',
        'difficulty',
        'score',
        'knowledge_tags',
    ];

    protected $casts = [
        'type' => QuestionType::class,
        'difficulty' => QuestionDifficulty::class,
        'score' => 'integer',
        'options' => 'array',
        'knowledge_tags' => 'array',
    ];

    /**
     * 关联课程
     */
    public function course(): BelongsTo
    {
        return $this->belongsTo(Course::class, 'course_id');
    }
}
