<?php

declare(strict_types=1);

namespace Kylin\Education\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
 * 作答答案明细
 */
class AttemptAnswer extends Model
{
    protected $table = 'attempt_answers';

    protected $fillable = [
        'attempt_id',
        'question_id',
        'answer',
        'is_correct',
        'score',
        'teacher_comment',
    ];

    protected $casts = [
        'is_correct' => 'boolean',
        'score' => 'decimal:1',
    ];

    public function attempt(): BelongsTo
    {
        return $this->belongsTo(Attempt::class, 'attempt_id');
    }

    public function question(): BelongsTo
    {
        return $this->belongsTo(Question::class, 'question_id');
    }
}
