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

import javax.inject.Inject;

import de.ivu.elect.business.konfiguration.entity.KonfigurationExtendedLoader;
import de.ivu.elect.business.konfiguration.entity.MandantKonfigurationWerte;
import de.ivu.elect.business.security.UseCasePermission;
import de.ivu.elect.business.security.entity.TwoFactorAuthenticationStatus;
import de.ivu.elect.presentation.mandant.MandantSessionSelect;
import de.ivu.elect.presentation.security.tfa.TfaSupported;

public class TfaVerwaltenMenuItemEntry extends AbstractNachrichtMenuItemEntry {

  private static final long serialVersionUID = 1L;

  @Inject
  private transient KonfigurationExtendedLoader konfigurationExtendedLoader;

  @Inject
  private transient MandantSessionSelect mandantSessionSelect;

  @Inject
  private transient TfaSupported tfaSupported;

  @Override
  protected UseCasePermission getUseCasePermission() {
    return UseCasePermission.TFA_SECRET_VERWALTEN;
  }

  @Override
  public boolean isRendered() {
    return super.isRendered() && tfaSupported.isTfaAvailable() && isTfaAktiv();
  }

  private boolean isTfaAktiv() {
    TwoFactorAuthenticationStatus twoFactorAuthenticationStatus = konfigurationExtendedLoader
        .resolveEnumValue(mandantSessionSelect.getMandant(), MandantKonfigurationWerte.TWO_FACTOR_AUTHENTICATION_STATUS,
            TwoFactorAuthenticationStatus.class);
    return twoFactorAuthenticationStatus != null && twoFactorAuthenticationStatus.isAktiv();
  }

  @Override
  public String getTargetViewId() {
    return tfaSupported.getTfaVerwaltenView();
  }

  @Override
  public String getLabelKey() {
    return "tfa.verwalten.menuitem.label";
  }

  @Override
  public String getIcon() {
    return "fa fa-user-secret";
  }
}
