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

import de.ivu.elect.business.konfiguration.entity.KonfigurationWertGeaendertEvent;
import de.ivu.elect.business.konfiguration.entity.MandantKonfigurationWerte;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.enterprise.event.Observes;
import javax.enterprise.event.Reception;
import javax.enterprise.event.TransactionPhase;
import java.io.Serializable;

public class UseCasePermissionAllowlistKonfigurationChangeListener implements Serializable {
  private static final Logger LOG = LoggerFactory.getLogger(UseCasePermissionAllowlistKonfigurationChangeListener.class);

  private static final long serialVersionUID = 1L;

  public void listen(@Observes(during = TransactionPhase.AFTER_COMPLETION, notifyObserver = Reception.ALWAYS) KonfigurationWertGeaendertEvent konfigurationWertGeaendertEvent) {
    try {
      if (MandantKonfigurationWerte.USECASE_ALLOWLIST_DEAKTIVIERT.equals(konfigurationWertGeaendertEvent.getKey())) {
        AbstractElectUseCasePermissionFilter.resetCache();
      }
    } catch (Exception e) {
      LOG.warn("Fehler:" + e.getMessage(), e);
    }
  }


}
