<?php

declare(strict_types=1);

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\SoftDeletes;

final class Paper extends Model
{
    use SoftDeletes;

    protected $fillable = ['owner_id', 'question_bank_id', 'title', 'description', 'duration_minutes', 'attempt_limit', 'is_active'];

    protected $casts = ['is_active' => 'boolean'];

    public function questions(): BelongsToMany
    {
        return $this->belongsToMany(Question::class, 'paper_questions')
            ->withPivot(['score', 'sort'])
            ->withTimestamps()
            ->orderByPivot('sort');
    }
}
