package de.ivu.elect.business.system.entity;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;

import de.ivu.elect.jee.performance.ViewAccessTarget;
import de.ivu.elect.jee.performance.ViewAccessTargetStatistics;

public enum PerformanceStatistikSessionType {

  ALLE {
    @Override
    public List<ViewAccessTargetStatistics> filterGruppiere(List<ViewAccessTargetStatistics> statistics, String sessionId) {
      return ViewAccessTargetStatistics.gruppiere(statistics, original -> ViewAccessTarget.copyNewSessionId(original, ViewAccessTarget.SESSION_ID_OHNE));
    }
  },
  AUSGEWAEHLTER_NUTZER {
    @Override
    public List<ViewAccessTargetStatistics> filterGruppiere(List<ViewAccessTargetStatistics> statistics, String sessionId) {
      if (StringUtils.isBlank(sessionId)) {
        return Collections.emptyList();
      }
      return ALLE
          .filterGruppiere(statistics.stream().filter(s -> sessionId.equals(s.getSessionId())).collect(Collectors.toList()), sessionId);
    }
  },
  ALLE_AKTIV {
    @Override
    public List<ViewAccessTargetStatistics> filterGruppiere(List<ViewAccessTargetStatistics> statistics, String sessionId) {
      return ALLE
          .filterGruppiere(statistics.stream().filter(s -> !ViewAccessTarget.SESSION_ID_OHNE.equals(s.getSessionId())).collect(Collectors.toList()), sessionId);
    }
  };

  public abstract List<ViewAccessTargetStatistics> filterGruppiere(List<ViewAccessTargetStatistics> statistics, String sessionId);
}
