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

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

import de.ivu.elect.business.security.UseCasePermission;
import de.ivu.elect.business.wahl.boundary.WahlChangeEvent;
import de.ivu.elect.business.wahl.boundary.WahlConversationSelect;
import de.ivu.elect.business.wahl.entity.Wahl;
import de.ivu.elect.presentation.menu.AbstractActionEntry;
import de.ivu.elect.presentation.security.AbstractGebietSecurity;

public abstract class AbstractWahlAction extends AbstractActionEntry<Wahl> {

  private static final long serialVersionUID = 1L;

  @Inject
  protected WahlConversationSelect wahlConversationSelect;

  @Inject
  private WahlChangeEvent changeEvent;

  public AbstractWahlAction() {
    super();
  }

  @Override
  protected AbstractGebietSecurity getGebietSecurity() {
    return KEINE_GEBIET_SECURITY;
  }

  @Override
  public abstract UseCasePermission getRequiredPermission();

  @Override
  public boolean isDisabledInternal(@Nonnull Wahl entity) {
    return !isRechtVorhanden(entity);
  }

  private boolean isRechtVorhanden(Wahl entity) {
    return entity.isRechtZumEinsehenVorhanden(principal);
  }

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

  @Override
  protected void fireChangeEvent() {
    changeEvent.sendChangeEvent();
  }

  @Override
  public abstract String doIt(Wahl wahl);

}
