package de.ivu.elect.presentation.email.exchange;

import de.ivu.elect.business.email.boundary.EmailVorlageExporter;
import de.ivu.elect.business.email.control.EmailVorlageExchangeContext;
import de.ivu.elect.business.email.entity.EmailVorlage;
import de.ivu.elect.business.exchange.control.AbstractExporter;
import de.ivu.elect.business.security.UseCasePermission;
import de.ivu.elect.business.wahl.entity.Wahl;
import de.ivu.elect.business.wahl.entity.Wahltermin;
import de.ivu.elect.presentation.View;
import de.ivu.elect.presentation.exchange.AbstractExportSearchView;
import de.ivu.elect.presentation.exchange.ExportDescription;
import de.ivu.elect.presentation.hilfe.OnlineHilfeId;

import javax.inject.Inject;
import javax.inject.Named;
import java.util.List;

@Named(EmailVorlageExportView.COMPONENT_NAME)
@View(viewId = EmailVorlageExportView.VIEW_ID, useCase = UseCasePermission.EMAIL_VORLAGE_EXPORTIEREN)
@OnlineHilfeId(value = "738", mehrfachVergebenOk = true)
public class EmailVorlageExportView extends AbstractExportSearchView<List<EmailVorlage>, EmailVorlageExchangeContext> {

  private static final long serialVersionUID = 1L;

  public static final String COMPONENT_NAME = "emailVorlageExportView";

  public static final String VIEW_ID = "/email/email-vorlage-export.xhtml";

  @Inject
  private transient EmailVorlageExporter emailVorlageExporter;

  @Inject
  private transient EmailVorlageExportDescription emailVorlageExportDescription;

  public EmailVorlageExportView() {
    super();
  }

  @Override
  protected EmailVorlageExchangeContext getContext() {
    Wahltermin selectedWahltermin = getSelectedWahltermin();
    Wahl selectedWahl = getSelectedWahl();
    if (selectedWahltermin == null && selectedWahl != null) {
      selectedWahltermin = selectedWahl.getWahltermin();
    }
    return new EmailVorlageExchangeContext(selectedWahltermin, selectedWahl);
  }

  @Override
  public ExportDescription getExportDescription() {
    return emailVorlageExportDescription;
  }

  @Override
  protected AbstractExporter<List<EmailVorlage>, EmailVorlageExchangeContext> getExporter() {
    return emailVorlageExporter;
  }

}
