class FormField < ApplicationRecord
  include Base::FormField

  enum type: {
    short_text: 1,
    long_text: 2,
    date: 3,
    checkbox: 4,
    horizontal_rule: 10,
    heading: 11,
    content: 12,
    subtitle: 13
  }

  belongs_to :form, foreign_key: :FormID, inverse_of: :fields

  has_many :answers, class_name: 'FormAnswer', foreign_key: :FormFieldID, dependent: :destroy,
    inverse_of: :field

  acts_as_list scope: :form, column: :Sequence

  validates :label, length: { maximum: 64 }
  validates :help_text, length: { maximum: 128 }

  scope :is_question, -> { where(type: 1..4) }
end
