
package de.ivu.elect.presentation.system;

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

import de.ivu.elect.business.security.UseCasePermission;
import de.ivu.elect.jee.database.DatabaseAvgTimeController;
import de.ivu.elect.jee.database.DatabaseCountController;
import de.ivu.elect.jee.database.DatabaseMaxTimeController;
import de.ivu.elect.jee.database.DatabaseStatistikData;
import de.ivu.elect.jee.database.DatabaseStatistikStore;
import de.ivu.elect.jee.faces.FacesMessageUtil;
import de.ivu.elect.jee.presentation.view.AbstractView;
import de.ivu.elect.presentation.View;
import de.ivu.elect.presentation.hilfe.OnlineHilfeId;

@RequestScoped
@OnlineHilfeId("820")
@Named(DatabaseMonitorView.COMPONENT_NAME)
@View(viewId = DatabaseMonitorView.VIEW_ID, useCase = UseCasePermission.DATABASE_MONITOR_SEARCH)
public class DatabaseMonitorView extends AbstractView {

  private static final long serialVersionUID = 1L;

  public static final String COMPONENT_NAME = "databaseMonitorView";

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

  @Inject
  private transient DatabaseCountController databaseCountController;

  @Inject
  private transient DatabaseMaxTimeController databaseMaxTimeController;

  @Inject
  private transient DatabaseAvgTimeController databaseAvgTimeController;

  @Inject
  private transient DatabaseStatistikStore databaseStatistikStore;

  public DatabaseMonitorView() {
    super();
  }

  public DatabaseCountController getDatabaseCountController() {
    return databaseCountController;
  }

  public DatabaseMaxTimeController getDatabaseMaxTimeController() {
    return databaseMaxTimeController;
  }

  public DatabaseAvgTimeController getDatabaseAvgTimeController() {
    return databaseAvgTimeController;
  }

  public void checkEnabled() {
    if (databaseStatistikStore.getData().stream().noneMatch(DatabaseStatistikData::isStatisticsEnabled)) {
      FacesMessageUtil.addWarnMessage("database.monitor.disabled");
    }
  }
}
