
package de.ivu.elect.presentation.dokumente.action;

import static org.apache.commons.lang3.StringUtils.isBlank;

import javax.inject.Inject;

import de.ivu.elect.business.security.UseCasePermission;
import de.ivu.elect.presentation.dokumente.exchange.DokumentBulkExportSearchEntry;
import de.ivu.elect.presentation.dokumente.menu.DokumentVorlageCreateMenuItemEntry;
import de.ivu.elect.presentation.security.AbstractGebietSecurity;

public class DokumentBulkExportSearchEntryDokumentVorlageCreateAction extends AbstractDokumentBulkExportSearchEntryDokumentVorlageAction {

  private static final long serialVersionUID = 1L;

  @Inject
  private transient DokumentVorlageCreateMenuItemEntry dokumentVorlageCreateMenuItemEntry;

  public DokumentBulkExportSearchEntryDokumentVorlageCreateAction() {
    super();
  }

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

  @Override
  protected AbstractGebietSecurity getGebietSecurity() {
    return dokumentVorlageCreateMenuItemEntry.getGebietSecurity();
  }

  @Override
  protected boolean isDisabledInternal(DokumentBulkExportSearchEntry dokumentBulkExportSearchEntry) {
    return super.isDisabledInternal(dokumentBulkExportSearchEntry) || dokumentBulkExportSearchEntry.isDokumentVorlagenConfigured() || dokumentVorlageCreateMenuItemEntry.isDisabled()
        || isBlank(getTargetViewId());
  }

  @Override
  protected String doIt(DokumentBulkExportSearchEntry dokumentBulkExportSearchEntry) {
    return getTargetViewId();
  }

  private String getTargetViewId() {
    return dokumentVorlageCreateMenuItemEntry.getTargetViewId();
  }

  @Override
  protected String getLocalizedLabel() {
    return dokumentVorlageCreateMenuItemEntry.getLabel();
  }

  @Override
  public String getLabelKey() {
    return dokumentVorlageCreateMenuItemEntry.getLabelKey();
  }

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