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

import de.ivu.elect.business.email.boundary.EmailVorlageImporter;
import de.ivu.elect.business.email.control.EmailVorlageExchangeContext;
import de.ivu.elect.business.exchange.control.AbstractImporter;
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.AbstractImportFormatFestlegenView;
import de.ivu.elect.presentation.exchange.ImportDescription;
import de.ivu.elect.presentation.hilfe.OnlineHilfeId;

import javax.inject.Inject;
import javax.inject.Named;

@Named(EmailVorlageImportFormatFestlegenView.COMPONENT_NAME)
@View(viewId = EmailVorlageImportFormatFestlegenView.VIEW_ID, useCase = UseCasePermission.EMAIL_VORLAGE_IMPORTIEREN)
@OnlineHilfeId(value = "738", mehrfachVergebenOk = true)
public class EmailVorlageImportFormatFestlegenView extends AbstractImportFormatFestlegenView<EmailVorlageExchangeContext> {

  private static final long serialVersionUID = 1L;

  public static final String COMPONENT_NAME = "emailVorlageImportFormatFestlegenView";

  public static final String VIEW_ID = "/email/email-vorlage-import-format-festlegen.xhtml";

  @Inject
  private transient EmailVorlageImportDescription emailVorlageImportDescription;

  @Inject
  private transient EmailVorlageImporter emailVorlageImporter;


  @Override
  protected ImportDescription getImportDescription() {
    return emailVorlageImportDescription;
  }

  @Override
  protected AbstractImporter<?, EmailVorlageExchangeContext, ?> getImporter() {
    return emailVorlageImporter;
  }

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