<?php

namespace App\Models;

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

class PaperQuestionRef extends Model
{
    use HasFactory;

    protected $table = 'paper_question_ref';

    protected $fillable = [
        'source_paper_id',
        'part_id',
        'candidate_id',
        'question_number',
        'order',
        'raw_markdown',
        'metadata',
    ];

    protected $casts = [
        'metadata' => 'array',
        'order' => 'integer',
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
    ];

    public function paper(): BelongsTo
    {
        return $this->belongsTo(SourcePaper::class, 'source_paper_id');
    }

    public function part(): BelongsTo
    {
        return $this->belongsTo(PaperPart::class, 'part_id');
    }

    public function candidate(): BelongsTo
    {
        return $this->belongsTo(PreQuestionCandidate::class, 'candidate_id');
    }
}
