class StudentMedical < ApplicationRecord
  audited

  include Base::StudentMedical

  enum exempt: { not_exempt: 0, exempt: 1, medical: 2, religious: 3, personal: 4 }

  AILMENTS = {
    asthma: 'Asthma',
    diabetes: 'Diabetes',
    seizures: 'Seizures',
    deafness: 'Hearing',
    sight_impairment: 'Sight',
    add: 'Add/Adhd',
    bladder: 'Bladder',
    sicklecell: 'Sicklecell',
    hemophiliac: 'Hemophiliac'
  }

  associations_for legacy: true do |a|
    a.belongs_to :school
    a.belongs_to :student, inverse_of: :student_medical
  end

  after_initialize :set_school, if: :new_record?

  validates :allergies, length: { maximum: 256 }

  before_save do
    self.updated = Time.current
  end

  private
    def set_school
      self.school_id = student.school_id unless school_id?
    end
end
