class Maintenance::EdFi::IdCleanupJob
  include Sidekiq::Worker

  def perform(id)
    edfi_id = EdFi::Id.find(id)
    school_year_id = case edfi_id.associated_type
    when 'Attendance', 'EdFi::StateProgram'
      edfi_id.associated.school_year_id
    else
      edfi_id.associated.school.id.current_year.id
    end

    edfi_id.school_year_id = school_year_id
    edfi_id.save
  end
end
