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.entity.SystemStatusOptionGroup;
import de.ivu.elect.jee.presentation.status.StatusEntry;
import de.ivu.elect.jee.presentation.status.StatusOptionType;

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

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

  @Inject
  SystemRequirements systemRequirements;

  @Override
  protected StatusEntry resolveSystemStatusOption(SystemStatusOption systemStatusOption) {

    int erwartet = systemRequirements.getAnzahlProzessorKerne();
    int vorhanden = Runtime.getRuntime().availableProcessors();
    if (vorhanden >= erwartet) {
      return ok("system.info.konfiguriert.cpu.ok", vorhanden);
    }
    return warn("system.info.konfiguriert.cpu.nok", vorhanden, erwartet);
  }

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

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

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


}
