class EducatorsImporter < Struct.new :school_scope, :client, :log, :progress_bar

  def remote_file_name
    'educators_export.txt'
  end

  def data_transformer
    CsvTransformer.new
  end

  def filter
    SchoolFilter.new(school_scope)
  end

  def school_ids_dictionary
    @dictionary ||= School.all.map { |school| [school.local_id, school.id] }.to_h
  end

  def import_row(row)
    educator = EducatorRow.new(row, school_ids_dictionary).build

    if educator.present?
      educator.save!
      educator.save_student_searchbar_json

      homeroom = Homeroom.find_by_name(row[:homeroom]) if row[:homeroom]
      homeroom.update(educator: educator) if homeroom.present?
    end
  end

end

class EducatorsImporter < Struct.new :school_scope, :client, :log, :progress_bar

  def remote_file_name
    'educators_export.txt'
  end

  def data_transformer
    CsvTransformer.new
  end

  def filter
    SchoolFilter.new(school_scope)
  end

  def school_ids_dictionary
    @dictionary ||= School.all.map { |school| [school.local_id, school.id] }.to_h
  end

  def import_row(row)
    educator = EducatorRow.new(row, school_ids_dictionary).build

    if educator.present?
      educator.save!

      homeroom = Homeroom.find_by_name(row[:homeroom]) if row[:homeroom]
      homeroom.update(educator: educator) if homeroom.present?
    end
  end

end

Remove student searchbar caching from educator import job
Remove student searchbar caching from educator import job

+ Good catch from @jhilde: this isn't needed on every import since all the main educator users of the platform have had this data precomputed for them with a background job.
+ https://github.com/studentinsights/studentinsights/issues/993#issuecomment-329496753
