
package de.ivu.elect.presentation.system;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;

import de.ivu.elect.business.security.UseCasePermission;
import de.ivu.elect.business.system.boundary.SystemUebersicht;
import de.ivu.elect.jee.presentation.status.StatusEntry;
import de.ivu.elect.jee.presentation.status.StatusOption;
import de.ivu.elect.jee.presentation.status.StatusOptionGroup;
import de.ivu.elect.presentation.AbstractElectView;
import de.ivu.elect.presentation.View;
import de.ivu.elect.presentation.hilfe.OnlineHilfeId;

/**
 *  on 08.06.2015.
 */
@OnlineHilfeId("695")
@RequestScoped
@Named(SystemUebersichtView.COMPONENT_NAME)
@View(viewId = SystemUebersichtView.VIEW_ID, useCase = UseCasePermission.SYSTEM_UEBERSICHT_ANZEIGEN)
public class SystemUebersichtView extends AbstractElectView {

  private static final long serialVersionUID = 1L;

  public static final String COMPONENT_NAME = "systemUebersichtView";

  public static final String VIEW_ID = "/system/system-uebersicht.xhtml";

  @Inject
  private transient SystemUebersicht systemUebersicht;

  private final Map<StatusOption, StatusEntry> entries = new ConcurrentHashMap<>();

  public List<StatusOptionGroup> getStatusOptionGroups() {
    return systemUebersicht.getStatusOptionGroups(getMandant());
  }

  public StatusEntry getStatus(StatusOption statusOption) {
    return entries.computeIfAbsent(statusOption, x -> systemUebersicht.ermittleStatus(statusOption));
  }

}
