package de.ivu.elect.business.system.control.status;

import java.util.Collections;
import java.util.List;

import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.ivu.elect.business.mandant.entity.Mandant;
import de.ivu.elect.business.system.control.WildFlyServer;
import de.ivu.elect.business.system.entity.SystemStatusOptionGroup;
import de.ivu.elect.jee.presentation.status.StatusEntry;
import de.ivu.elect.jee.presentation.status.StatusOptionType;

/**
 *  on 26.05.2017.
 */
public class WildFlyHttpHttpPushSystemStatusOptionResolver extends AbstractSystemStatusOptionResolver {

  private static final Logger LOG = LoggerFactory.getLogger(WildFlyHttpHttpPushSystemStatusOptionResolver.class);

  private static final StatusOptionType WILDFLY_HTTP_HTTP2_PUSH_PARAMETERS = new StatusOptionType() {
  };

  @Inject
  private transient WildFlyServer wildFlyServer;

  @Override
  protected StatusEntry resolveSystemStatusOption(SystemStatusOption systemStatusOption) {

    boolean httpHttp2Enabled = wildFlyServer.isHttpHttp2Enabled();
    boolean httpHttp2PushEnabled = wildFlyServer.isHttpHttp2PushEnabled();

    LOG.info("httpHttp2Enabled="+httpHttp2Enabled+", httpHttp2PushEnabled="+httpHttp2PushEnabled);

    if (!httpHttp2Enabled || !httpHttp2PushEnabled) {
      return ok("system.info.konfiguriert.http.http2.push.ok");
    }
    return warn/*Warnung, weil Log mit dubiosen Fehlern vollgeschrieben, wenn aktiviert*/("system.info.konfiguriert.http.http2.push.nok");
  }

  @Override
  protected boolean isAccept(Mandant mandant) {
    return mandant.getArt().isSystemMandant();
  }

  @Override
  protected List<SystemStatusOption> getStatusOptionsInternal(Mandant mandant) {
    return Collections.singletonList(new SystemStatusOption(WILDFLY_HTTP_HTTP2_PUSH_PARAMETERS, mandant));
  }

  @Override
  public SystemStatusOptionGroup getSystemStatusOptionGroup() {
    return SystemStatusOptionGroup.APPSERVER_KONFIGURATION;
  }

}
