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

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.ExportDescription;

public abstract class AbstractExportMenuItemEntry extends AbstractImportExportMenuItemEntry {

  private static final long serialVersionUID = 1L;

  @Inject
  private transient WahlSessionSelector wahlSelect;

  @Inject
  private transient WahlterminSessionSelect wahlterminSelect;

  public AbstractExportMenuItemEntry() {
    super();
  }

  protected abstract ExportDescription getExportDescription();

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

  @Override
  protected boolean isDisabledInternal() {
    if (getExportDescription().isSpecificPerWahltermin() && !isWahlterminSelected() || getExportDescription().isSpecificPerWahl() && !isWahlSelected()) {
      return true;
    }

    return false;
  }

  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 getExportDescription().getExportSearchViewId();
  }

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

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