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

import de.ivu.elect.business.security.UseCasePermission;
import de.ivu.elect.business.wahl.boundary.WahlExtendedDAO;
import de.ivu.elect.business.wahl.boundary.WahlkonfigurationAnpassbar;
import de.ivu.elect.business.wahl.entity.Wahlart;

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

@Named(WahlartDeleteAction.COMPONENT_NAME)
public class WahlartDeleteAction extends AbstractWahlartAction {

  private static final long serialVersionUID = 1L;

  public static final String COMPONENT_NAME = "wahlartDeleteAction";

  @Inject
  private transient WahlkonfigurationAnpassbar wahlkonfigurationAnpassbar;

  @Inject
  private transient WahlExtendedDAO wahlExtendedDAO;

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

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

  @Override
  protected String doIt(Wahlart entity) {
    conversationSelect.setEntity(entity);

    // 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 Wahlart entity) {
    return super.isDisabledInternal(entity) || !wahlkonfigurationAnpassbar.isWahlkonfigurationAnpassbar(entity.getMandant()) || wahlExtendedDAO.findByCountWahlart(entity) > 0;
  }
}
