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

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

import de.ivu.elect.business.datei.entity.DateiExport;
import de.ivu.elect.business.exchange.control.AbstractExporter;
import de.ivu.elect.business.exchange.control.ExportExchange;
import de.ivu.elect.business.exchange.control.FileFormat;
import de.ivu.elect.business.exchange.entity.DateiExportArt;
import de.ivu.elect.business.internet.control.PraesentationExportContext;
import de.ivu.elect.business.internet.control.PraesentationExportExchange;
import de.ivu.elect.business.internet.control.PraesentationExportObject;
import de.ivu.elect.business.internet.control.PraesentationExportObjectErzeuger;
import de.ivu.elect.business.praesentation.boundary.PraesentationStatistikStore;
import de.ivu.elect.business.praesentation.entity.PraesentationStatistik;

@Stateless
public class PraesentationExporter extends AbstractExporter<PraesentationExportObject, PraesentationExportContext> {

  @Inject
  private transient PraesentationExportExchange exportExchange;

  @Inject
  private transient PraesentationExportObjectErzeuger praesentationExportObjectErzeuger;

  @Inject
  private transient PraesentationStatistikStore praesentationStatistikStore;

  @Override
  protected ExportExchange<PraesentationExportObject, PraesentationExportContext> getExchange() {
    return exportExchange;
  }

  @Override
  protected PraesentationExportObject getExportObject(PraesentationExportContext praesentationExportContext) {
    throw new UnsupportedOperationException("Methode nicht unterstützt");
  }

  @Override
  protected PraesentationExportObject getExportObject(PraesentationExportContext praesentationExportContext,
                                                      FileFormat fileFormat, DateiExport dateiExport) {
    PraesentationStatistik praesentationStatistik = praesentationStatistikStore.getPraesentationStatistik(praesentationExportContext.getErgebnis().getPk());
    praesentationStatistik.startDatenLaden();
    try {
      return praesentationExportObjectErzeuger.getExportObject(praesentationExportContext, fileFormat, dateiExport);
    } finally {
      praesentationStatistik.endeDatenLaden();
    }
  }

  public boolean isMapperVorhanden(PraesentationExportContext praesentationExportContext, FileFormat fileFormat) {
    return getSupportedFileFormats(praesentationExportContext).contains(fileFormat);
  }

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