class Covid::FormQuestion < Covid::FormField
  enum field: [:short_text, :long_text, :multi_choice, :checkbox]

  belongs_to :section, class_name: 'Covid::FormSection'

  has_many :answers, foreign_key: :question_id, class_name: 'Covid::Answer', dependent: :destroy
  has_many :employee_answers, foreign_key: :question_id, class_name: 'Covid::EmployeeAnswer',
    dependent: :destroy
  has_many :options, foreign_key: :field_id, class_name: 'Covid::FormOption',
    autosave: true, validate: false, dependent: :destroy

  accepts_nested_attributes_for :options, allow_destroy: true

  validates :title, length: { maximum: 256 }

  def has_options?
    multi_choice? || checkbox?
  end
end
