class Form < ApplicationRecord
  include Base::Form

  associations_for legacy: true do |a|
    a.belongs_to :school
  end

  has_many :fields, -> { order(:position) }, class_name: '::FormField', dependent: :destroy,
    inverse_of: :form
  has_many :entries, class_name: '::FormEntry', dependent: :destroy, inverse_of: :form

  belongs_to :notifier, class_name: 'User', foreign_key: :PANID, inverse_of: :forms

  scope :active, -> { where(active: true) }
  scope :public_view, -> { where(public: true) }
  scope :exclude_internal, ->(flag) { where.not(internal: true) if flag }

  validates :name, presence: true, length: { maximum: 32 }
  validates :description, length: { maximum: 128 }
end
