<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class FormQuestion extends Model
{
    protected $fillable = [
        'form_id', 'question_text', 'question_type', 
        'options', 'order', 'is_required'
    ];

    protected $casts = [
        'options' => 'array',
        'is_required' => 'boolean',
    ];

    public function form()
    {
        return $this->belongsTo(EvaluationForm::class, 'form_id');
    }

    public function competencyTags()
    {
        return $this->hasMany(QuestionCompetencyTag::class, 'question_id');
    }

    public function competencies()
    {
        return $this->belongsToMany(Competency::class, 'question_competency_tags')
                    ->withPivot('weight')
                    ->withTimestamps();
    }

    public function responses()
    {
        return $this->hasMany(FormResponse::class, 'question_id');
    }
}
