package de.ivu.elect.business.security.control;

import java.util.Collection;
import java.util.Collections;

import de.ivu.elect.business.konfiguration.control.AbstractKonfigurationInit;
import de.ivu.elect.business.konfiguration.entity.Konfiguration;
import de.ivu.elect.business.konfiguration.entity.KonfigurationInitContext;
import de.ivu.elect.business.konfiguration.entity.MandantKonfigurationWerte;


import static de.ivu.elect.business.ElectSystemProperties.ELECT_USECASE_ALLOWLIST_DEAKTIVIERBAR;

public class UseCasePermissionAllowlistKonfigurationInit extends AbstractKonfigurationInit {

  @Override
  protected Collection<Konfiguration> createDefaultParameters(KonfigurationInitContext konfigurationInitContext) {
    // Parameter nur über System-Property freischaltbar
    if (!UseCasePermissionAllowlist.DEAKTIVIERT && isAllowListPropertySet()) {
      return Collections.singletonList(create(MandantKonfigurationWerte.USECASE_ALLOWLIST_DEAKTIVIERT, false));
    }
    return Collections.emptySet();
  }

  private boolean isAllowListPropertySet() {
    return Boolean.TRUE.toString().equalsIgnoreCase(System.getProperty(ELECT_USECASE_ALLOWLIST_DEAKTIVIERBAR)) ||
        Boolean.TRUE.toString().equalsIgnoreCase(System.getProperty("elect.usecase.whitelist.deaktivierbar")) /*deprecated*/;
  }

}
