class Maintenance::Covid::SchoolYearCleanupJob
  include Sidekiq::Worker

  def perform(school_id, school_year_id)
    @school = School.find(school_id)
    @school_year = @school.school_years.find(school_year_id)

    temperatures.delete_all
    screenings.destroy_all
  end

  private
    def school_year_range
      first_day = @school_year.school_days.ordered.limit(1).first
      last_day = @school_year.school_days.order(date: :desc).limit(1).first
      first_day.date.beginning_of_day..last_day.date.end_of_day
    end

    def temperatures
      @school.covid_temperatures.by_date_range(school_year_range)
    end

    def screenings
      @school.covid_screenings.by_date_range(school_year_range)
    end
end
