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

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

import de.ivu.elect.business.kandidatur.boundary.KandidaturConversationSelect;
import de.ivu.elect.business.kandidatur.entity.Listenkandidatur;
import de.ivu.elect.business.security.UseCasePermission;
import de.ivu.elect.presentation.kandidatur.ErsatzkandidaturCreateViewResolver;

@Named(ListenkandidaturErsatzkandidaturCreateAction.COMPONENT_NAME)
public class ListenkandidaturErsatzkandidaturCreateAction extends AbstractListenkandidaturAction {

  private static final long serialVersionUID = 1L;

  public static final String COMPONENT_NAME = "listenkandidaturErsatzkandidaturCreateAction";

  @Inject
  private transient KandidaturConversationSelect uebergeordneteKandidaturSelect;

  @Inject
  private transient ErsatzkandidaturCreateViewResolver ersatzkandidaturCreateViewResolver;

  public ListenkandidaturErsatzkandidaturCreateAction() {
    super();
  }

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

  @Override
  public boolean isDisabledInternal(Listenkandidatur listenkandidatur) {
    return super.isDisabledInternal(listenkandidatur) || !ersatzkandidaturCreateViewResolver.isUntergeordneteErsatzkandidaturCreatable(listenkandidatur.getWahl(), listenkandidatur);
  }

  @Override
  protected String doIt(Listenkandidatur listenkandidatur) {
    uebergeordneteKandidaturSelect.setEntity(listenkandidatur);

    return ersatzkandidaturCreateViewResolver.getViewId(getMandant(listenkandidatur));
  }

  @Override
  public String getLabelKey() {
    return "listenkandidatur.edit.action.ersatzkandidatur.create";
  }

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