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

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;

import de.ivu.elect.business.praesentation.entity.PraesentationUploadServiceTyp;

@RequestScoped
public class PraesentationUploadServiceFinder implements Serializable {

  private static final long serialVersionUID = 1L;

  @Inject
  private transient Instance<PraesentationUploadService> services;

  @Inject
  private transient DeaktiviertPraesentationUploadService deaktiviertPraesentationUploadService;

  public Set<PraesentationUploadServiceTyp> getSupportedTypes() {
    Set<PraesentationUploadServiceTyp> result = new HashSet<>();

    for (PraesentationUploadService service : services) {
      result.add(service.getPraesentationUploadServiceTyp());
    }

    return result;
  }

  public PraesentationUploadService getPraesentationUploadService(PraesentationUploadServiceTyp praesentationUploadServiceTyp) {
    for (PraesentationUploadService service : services) {
      if (praesentationUploadServiceTyp.equals(service.getPraesentationUploadServiceTyp())) {
        return service;
      }
    }
    return deaktiviertPraesentationUploadService; // fallback
  }

}
