package de.ivu.elect.business.security.control;

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

import javax.inject.Inject;

import de.ivu.elect.business.konfiguration.entity.CustomParameterFilter;
import de.ivu.elect.business.konfiguration.entity.Konfiguration;
import de.ivu.elect.business.security.entity.LoginServiceName;
import de.ivu.elect.jee.security.LoginServiceFinder;

public class LoginServiceNameFilter implements CustomParameterFilter<Konfiguration, LoginServiceName> {

  @Inject
  private transient LoginServiceFinder loginServiceFinder;

  @Override
  public List<LoginServiceName> filter(Konfiguration customParameter, List<LoginServiceName> values) {
    Set<String> registerServiceNames = loginServiceFinder.getRegisterServiceNames();
    return values.stream().filter(value -> registerServiceNames.contains(value.name())).collect(Collectors.toList());
  }
}
