<?php

namespace App\Models;

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

class QuestionnaireSet extends Model
{
    use HasFactory;

    protected $fillable = ['title', 'description', 'status', 'created_by'];

    public function creator()
    {
        return $this->belongsTo(User::class, 'created_by');
    }

    public function questions()
    {
        return $this->hasMany(QuestionnaireQuestion::class)->orderBy('sort_order');
    }

    public function programs()
    {
        return $this->belongsToMany(Program::class, 'program_questionnaires')
                    ->withPivot(['is_confirmed', 'confirmed_at', 'confirmed_by'])
                    ->withTimestamps();
    }

    public function programQuestionnaires()
    {
        return $this->hasMany(ProgramQuestionnaire::class);
    }

    public function responses()
    {
        return $this->hasMany(QuestionnaireResponse::class);
    }
}
