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

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

import de.ivu.elect.business.mandant.entity.Mandant;
import de.ivu.elect.business.security.UseCasePermission;
import de.ivu.elect.presentation.View;
import de.ivu.elect.presentation.mandant.MandantEditView;

@Named(MandantDeleteAction.COMPONENT_NAME)
public class MandantDeleteAction extends AbstractMandantAction {

  public static final String COMPONENT_NAME = "mandantDeleteAction";

  private static final long serialVersionUID = 1L;

  @View
  @Inject
  private MandantEditView editView;

  public MandantDeleteAction() {
    super();
  }

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

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

  @Override
  protected String doIt(Mandant mandant) {
    editView.setEntity(mandant);

    // Return to current page and display the dialog!
    return null;
  }

  @Override
  public String getDialogName() {
    return "DeleteConfirm";
  }

  @Override
  public String getLabelKey() {
    return "entity.edit.action.delete";
  }

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

  @Override
  public boolean isDisabledInternal(@Nonnull Mandant mandant) {
    return super.isDisabledInternal(mandant) || mandant.getArt().isSystemMandant();
  }
}
