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

import java.util.ArrayList;
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.kandidatur.control.KandidaturExportContext;
import de.ivu.elect.business.kandidatur.control.KandidaturExportExchange;
import de.ivu.elect.business.kandidatur.entity.Kandidatur;
import de.ivu.elect.business.wahl.boundary.WahlDAO;
import de.ivu.elect.business.wahl.entity.Wahl;

@Stateless
public class KandidaturExporter extends AbstractExporter<List<Kandidatur>, KandidaturExportContext> {

  @Inject
  private transient KandidaturExportExchange kandidaturExportExchange;

  @Inject
  private transient  WahlDAO wahlDAO;

  @Inject
  private transient  KandidaturDAO kandidaturDAO;

  public KandidaturExporter() {
    super();
  }

  @Override
  public ExportExchange<List<Kandidatur>, KandidaturExportContext> getExchange() {
    return kandidaturExportExchange;
  }

  @Override
  public List<Kandidatur> getExportObject(KandidaturExportContext context) {
    Wahl wahl = wahlDAO.attach(context.getWahl());
    return new ArrayList<>(kandidaturDAO.findByWahl(wahl)/*ELECTKOM-117*/.stream().filter(k->k.getWahlvorschlag()!=null).collect(Collectors.toList()));
  }

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

  @Override
  protected boolean isExportHeader() {
    return true;
  }
}
