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

import javax.annotation.Nonnull;
import javax.inject.Inject;

import de.ivu.elect.business.person.boundary.PersonendatenConversationSelect;
import de.ivu.elect.business.person.entity.Personendaten;
import de.ivu.elect.business.person.entity.PersonendatenDateiExportConstants;
import de.ivu.elect.business.security.UseCasePermission;
import de.ivu.elect.jee.entity.Entity;
import de.ivu.elect.presentation.menu.AbstractActionEntry;

public abstract class AbstractEntityPersonendatenDateiExportSearchAction<E extends Entity< ? , ? >> extends AbstractActionEntry<E> {

  private static final long serialVersionUID = 1L;

  @Inject
  private transient PersonendatenConversationSelect personendatenConversationSelect;

  protected AbstractEntityPersonendatenDateiExportSearchAction() {
    super();
  }

  @Override
  public boolean hasPrincipalRequiredPermission() {
    return super.hasPrincipalRequiredPermission() && principal.hasUseCasePermission(getRequiredPersonendatenPermission());
  }

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

  protected abstract UseCasePermission getRequiredPersonendatenPermission();

  @Override
  public boolean isDisabledInternal(@Nonnull E personendaten) {
    return false;
  }

  @Override
  protected String doIt(E entity) {
    personendatenConversationSelect.setEntity(attachPersonendaten(entity));

    return getGoToSearchViewId();
  }

  protected abstract Personendaten attachPersonendaten(E entity);

  protected abstract String getGoToSearchViewId();

  @Override
  protected boolean isFireChangeEvent() {
    return false;
  }

  @Override
  protected void fireChangeEvent() {
    // Do nothing.
  }

  @Override
  protected String getLocalizedLabel() {
    return getMessage(getLabelKey(), getMessage(PersonendatenDateiExportConstants.MESSAGE_KEY_ENTITY_MEHRZAHL));
  }

  @Override
  public String getLabelKey() {
    return "entity.edit.action.go.to.next.view.search";
  }

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