<?php

declare(strict_types=1);

namespace App\Models;

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

final class QuizAttempt extends Model
{
    protected $fillable = [
        'user_id',
        'paper_id',
        'question_bank_id',
        'mode',
        'status',
        'draw_rule',
        'started_at',
        'expires_at',
        'submitted_at',
        'score',
        'total_questions',
        'correct_count',
        'current_index',
    ];

    protected $casts = [
        'draw_rule' => 'array',
        'started_at' => 'datetime',
        'expires_at' => 'datetime',
        'submitted_at' => 'datetime',
        'score' => 'decimal:2',
    ];

    public function items(): HasMany
    {
        return $this->hasMany(QuizAttemptQuestion::class)->orderBy('sort');
    }
}
