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

import static java.util.Arrays.asList;

import java.util.List;

import javax.inject.Inject;

import de.ivu.elect.business.security.UseCasePermission;
import de.ivu.elect.business.wahl.boundary.WahlSessionSelector;
import de.ivu.elect.business.wahl.boundary.WahlterminSessionSelect;
import de.ivu.elect.business.wahl.entity.Wahl;
import de.ivu.elect.business.wahl.entity.Wahltermin;
import de.ivu.elect.presentation.exchange.ImportDescription;

/**
 * Erbt UseCasePermission, TargetViewId und AdditionalTopicViewIds von der jeweiligen ImportDescription. Hat sinnvolle
 * Default-Werte für Icon und Label.
 *
 *  on 15.03.2017.
 */
public abstract class AbstractImportMenuItemEntry extends AbstractImportExportMenuItemEntry {

  private static final long serialVersionUID = 1L;

  @Inject
  private transient WahlSessionSelector wahlSelect;

  @Inject
  private transient WahlterminSessionSelect wahlterminSelect;

  public AbstractImportMenuItemEntry() {
    super();
  }

  protected abstract ImportDescription getImportDescription();

  @Override
  protected UseCasePermission getUseCasePermission() {
    return getImportDescription().getUseCasePermission();
  }

  @Override
  protected boolean isDisabledInternal() {
    return getImportDescription().isSpecificPerWahlOrWahltermin() && !isWahlterminSelected() && !isWahlSelected();
  }

  protected boolean isWahlterminSelected() {
    return wahlterminSelect.isSelected();
  }

  protected Wahltermin getSelectedWahltermin() {
    return wahlterminSelect.getEntity();
  }

  protected boolean isWahlSelected() {
    return wahlSelect.isSelected();
  }

  protected Wahl getSelectedWahl() {
    return wahlSelect.getEntity();
  }

  @Override
  public String getTargetViewId() {
    return getImportDescription().getImportSearchViewId();
  }

  @Override
  protected List<String> getAdditionalTopicViewIds() {
    return asList(getImportDescription().getImportFormatFestlegenViewId(), getImportDescription().getImportBestaetigenViewId());
  }

  @Override
  public String getLabelKey() {
    return "entity.import.menu.item.label";
  }

  @Override
  public String getIcon() {
    return getIcons().getIconImport();
  }
}
