
package de.ivu.elect.business.konfiguration.boundary;

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

import javax.ejb.Stateless;
import javax.inject.Inject;

import de.ivu.elect.business.exchange.control.AbstractExporter;
import de.ivu.elect.business.exchange.control.ExportExchange;
import de.ivu.elect.business.exchange.entity.DateiExportArt;
import de.ivu.elect.business.konfiguration.control.KonfigurationExportExchange;
import de.ivu.elect.business.konfiguration.entity.Konfiguration;
import de.ivu.elect.business.konfiguration.entity.KonfigurationExchangeContext;

@Stateless
public class KonfigurationExporter extends AbstractExporter<List<Konfiguration>, KonfigurationExchangeContext> {

  @Inject
  private transient KonfigurationDAO konfigurationDAO;

  @Inject
  private transient KonfigurationExportExchange konfigurationExportExchange;

  public KonfigurationExporter() {
    super();
  }

  @Override
  protected ExportExchange<List<Konfiguration>, KonfigurationExchangeContext> getExchange() {
    return konfigurationExportExchange;
  }

  @Override
  protected List<Konfiguration> getExportObject(KonfigurationExchangeContext context) {
    return filterElectKonfigurationWerte(konfigurationDAO.findByMandant(context.getMandant()));
  }

  private List<Konfiguration> filterElectKonfigurationWerte(List<Konfiguration> entities) {
    // ELECT-1069
    return entities.stream().filter(entity -> entity.getTemplate().isPresent()).collect(Collectors.toList());
  }

  @Override
  protected DateiExportArt getDateiExportArt() {
    return DateiExportArt.KONFIGURATION_EXPORT;
  }
}
