class EdFi::Accommodation < ApplicationRecord
  audited

  enum assessment: {
    i_am: 0,
    ilearn: 1,
    iread_3: 2,
    wida: 3,
    ilearn_biology: 4, #v2026 assessments start here
    ilearn_english: 5,
    ilearn_life: 6,
    ilearn_math: 7,
    ilearn_social: 8,
    ilearn_government: 9,
    iread: 10
  }

  belongs_to :student, inverse_of: :ed_fi_accommodations
  belongs_to :school_year, inverse_of: :ed_fi_accommodations
  
  has_one :school, through: :school_year

  associations_for namespace: 'EdFi' do |a|
    a.has_many :logs, as: :associated, inverse_of: :associated

    a.has_one :id, as: :associated, inverse_of: :associated, dependent: :destroy
  end

  validates :assessment, :accommodation_descriptor, presence: true
  validates :academic_subject_descriptor, presence: true,
    unless:-> { school.find_or_build_ed_fi_indiana_environment.environment == 'v2026' }

  scope :ordered, -> { order(assessment: :asc) }
  scope :by_assessment, ->(assessment) { where(assessment: assessment) if assessment }
  scope :by_year, ->(year) { where(school_year: year) if year }
end
