<?php

namespace App\Models;

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

class AssessmentQuestion extends Model
{
    public const TYPE_TEXT = 'text';

    public const TYPE_TEXTAREA = 'textarea';

    public const TYPE_NUMBER = 'number';

    public const TYPE_INTEGER = 'integer';

    public const TYPE_BOOLEAN = 'boolean';

    public const TYPE_DATE = 'date';

    public const TYPE_DATETIME = 'datetime';

    public const TYPE_SINGLE_CHOICE = 'single_choice';

    public const TYPE_MULTI_CHOICE = 'multi_choice';

    public const TYPE_SCALE = 'scale';

    public const TYPE_SCORE_ITEM = 'score_item';

    public const TYPE_CALCULATED = 'calculated';

    protected $table = 'care_assessment_questions';

    protected $fillable = [
        'template_id', 'code', 'section', 'label', 'help_text', 'answer_type',
        'options', 'is_required', 'sort_order', 'score_key', 'validation',
    ];

    protected function casts(): array
    {
        return [
            'options' => 'array',
            'validation' => 'array',
            'is_required' => 'boolean',
            'sort_order' => 'integer',
        ];
    }

    public function template(): BelongsTo
    {
        return $this->belongsTo(AssessmentTemplate::class, 'template_id');
    }

    public function answers(): HasMany
    {
        return $this->hasMany(AssessmentAnswer::class, 'question_id');
    }
}
