module Base::FormAnswer
  extend ActiveSupport::Concern
  include Castable

  included do
    cast_as_boolean :CheckBoxField

    self.table_name = 'FormData'
    self.primary_key = 'FormDataID'

    alias_attribute :id, :FormDataID
    alias_attribute :school_id, :SchoolID
    alias_attribute :user_id, :UserID
    alias_attribute :form_id, :FormID
    alias_attribute :entry_id, :FormEntryID
    alias_attribute :field_id, :FormFieldID
    alias_attribute :short_text, :TextField
    alias_attribute :long_text, :LongTextField
    alias_attribute :date, :DateField
    alias_attribute :checkbox, :CheckBoxField

    before_save :set_defaults

    private
      def set_defaults
        self.short_text = '' if short_text.nil?
        self.long_text = '' if long_text.nil?
      end
  end
end
