package de.ivu.elect.presentation.dashboard.entries;

import de.ivu.elect.business.system.entity.LogNachrichtArt;
import de.ivu.elect.jee.presentation.dynamicform.FormBuilder;
import de.ivu.elect.jee.presentation.dynamicform.ReadOnlyLongProperty;
import de.ivu.elect.jee.presentation.status.OutputSeverity;
import de.ivu.elect.presentation.menu.AbstractMenuItemEntry;
import de.ivu.elect.presentation.system.menu.SystemLogUnbestaetigtSearchMenuItemEntry;

import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class SystemLogDashboardEntry extends AbstractDashboardEntry {

  private static final long serialVersionUID = 1L;

  @Override
  public String getLegend() {
    return getMessage("dashboard.system.log.legend");
  }

  @Inject
  private transient SystemLogUnbestaetigtSearchMenuItemEntry systemLogUnbestaetigtSearchMenuItemEntry;

  @Override
  protected void addProperties(FormBuilder formBuilder) {
    if (systemLogUnbestaetigtSearchMenuItemEntry.isPossible()) {
      formBuilder.addSeparator("dashboard.system.log.unbestaetigt.separator");
      Map<LogNachrichtArt, Long> countNachArt = systemLogUnbestaetigtSearchMenuItemEntry.getCountNachArt();
      for (LogNachrichtArt logNachrichtArt : LogNachrichtArt.values()) {
        Long value = countNachArt.get(logNachrichtArt);
        if (value != null && value > 0L) {
          formBuilder.addProperty(new ReadOnlyLongProperty(getMessage(logNachrichtArt), value));
        }
      }

    }
  }

  @Override
  public List<AbstractMenuItemEntry> getMenuItemsFirst() {
    List<AbstractMenuItemEntry> result = new ArrayList<>();
    result.add(systemLogUnbestaetigtSearchMenuItemEntry);
    return result;
  }

  @Override
  public List<AbstractMenuItemEntry> getMenuItemsLast() {
    return Collections.emptyList();
  }

  @Override
  protected OutputSeverity getSeverity() {
    return OutputSeverity.WARN;
  }
}
