class SchoolYearFamilyCleanupService < ApplicationService
  def initialize(school)
    @school = school
  end

  def call
    @school.school_year_families
      .where.not(id: unique_ids)
      .delete_all
  end

  private
    def unique_ids
      @school.school_year_families.group(:FamilyID, :SchoolYearID).select('min(SchoolYearFamilyID)').pluck(:id)
    end
end
