package de.ivu.elect.presentation.email.menu;

import de.ivu.elect.business.email.entity.EmailVorlageMeta;
import de.ivu.elect.business.security.UseCasePermission;
import de.ivu.elect.business.wahl.boundary.WahlSessionSelector;
import de.ivu.elect.business.wahl.boundary.WahlterminSessionSelect;
import de.ivu.elect.business.wahl.entity.Wahl;
import de.ivu.elect.presentation.menu.AbstractMenuItemEntry;
import de.ivu.elect.presentation.security.AbstractGebietSecurity;

import javax.inject.Inject;

public abstract class AbstractEmailVorlageMenuItemEntry extends AbstractMenuItemEntry {

  private static final long serialVersionUID = 1L;

  @Inject
  private EmailVorlageMeta emailVorlageMeta;

  @Inject
  private transient WahlSessionSelector wahlSelect;

  @Inject
  private transient WahlterminSessionSelect wahlterminSelect;

  public AbstractEmailVorlageMenuItemEntry() {
    super();
  }

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

  @Override
  public boolean isRendered() {
    return hasUseCasePermission(getUseCasePermission());
  }

  protected abstract UseCasePermission getUseCasePermission();

  @Override
  public boolean isDisabledInternal() {
    return !isWahlterminSelected() && !isWahlSelected();
  }

  protected EmailVorlageMeta getMeta() {
    return emailVorlageMeta;
  }

  protected boolean isWahlterminSelected() {
    return wahlterminSelect.isSelected();
  }

  protected boolean isWahlSelected() {
    return wahlSelect.isSelected();
  }
}
