/*
 * (c) 2020 Pluto Inc.
 */
package tv.pluto.mongo.utils;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import tv.pluto.mongo.entities.activeregions.ActiveRegions;

public class ActiveRegionsUtils extends MongoUtils {

  public ActiveRegionsUtils() {
    this.genericCollection = this.collectionActiveRegions;
    this.setContentFeedsDates();
  }

  public ActiveRegions getRandomRegion() {
    return getRandomItem(getActiveRegions(10));
  }

  public List<ActiveRegions> getActiveRegions(int limit) {
    List<ActiveRegions> result = new ArrayList<>();
    collectionActiveRegions.find().limit(limit).forEach(result::add);
    return result;
  }

  public List<ActiveRegions> getAllActiveRegionsWithingUpdatedDate(LocalDateTime time) {
    List<ActiveRegions> result = new ArrayList<>();
    collectionActiveRegions
        .find()
        .forEach(
            region -> {
              if (region.getUpdatedAt().equals(time) || region.getUpdatedAt().isAfter(time))
                result.add(region);
            });
    return result;
  }
}
