<?php

declare(strict_types=1);

namespace App\Models;

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

final class Question extends Model
{
    use HasFactory;

    /**
     * Fillable attributes for mass assignment.
     */
    protected $fillable = [
        'question_group_id',
        'text',
        'has_yes',
        'has_no',
        'has_na',
        'details',
        'sort_order',
        'is_scored',
    ];

    /**
     * Cast attributes to specific types.
     */
    protected function casts(): array
    {
        return [
            'question_group_id' => 'integer',
            'has_yes' => 'boolean',
            'has_no' => 'boolean',
            'has_na' => 'boolean',
            'sort_order' => 'integer',
            'is_scored' => 'boolean',
        ];
    }

    /**
     * Get the question group that owns this question.
     */
    public function questionGroup(): BelongsTo
    {
        return $this->belongsTo(QuestionGroup::class);
    }

    /**
     * Get all answers for this question.
     */
    public function answers(): HasMany
    {
        return $this->hasMany(Answer::class);
    }
}
