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

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

import javax.inject.Inject;

import de.ivu.elect.business.mandant.entity.Mandant;
import de.ivu.elect.business.system.control.SystemRequirements;
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 WildFlyDsMaxPoolsizeSystemStatusOptionResolver extends AbstractSystemStatusOptionResolver {

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

  @Inject
  private transient SystemRequirements systemRequirements;

  @Inject
  private transient WildFlyServer wildFlyServer;

  @Override
  protected StatusEntry resolveSystemStatusOption(SystemStatusOption systemStatusOption) {
    long erwartet = systemRequirements.getMaximumMaxPoolSize();
    long vorhanden = wildFlyServer.getMaxPoolSize();
    if (vorhanden < erwartet) {
      return warn("system.info.konfiguriert.maxpoolsize.nok", vorhanden, erwartet);
    }

    return ok("system.info.konfiguriert.maxpoolsize.ok", vorhanden);
  }

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

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

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

}
