package de.ivu.elect.presentation.praesentation.table;

import java.util.function.Function;

import javax.annotation.Nullable;

import de.ivu.elect.business.praesentation.entity.PraesentationStatistikSearchResult;
import de.ivu.elect.jee.faces.Messages;
import de.ivu.elect.jee.presentation.dynamictable.ColumnType;
import de.ivu.elect.presentation.table.DefaultColumnEntry;


import static de.ivu.elect.presentation.praesentation.table.PraesentationStatistikColumnBuilder.findeLetztenEintrag;

public class PraesentationStatistikGenerierungZeitstempelColumn extends DefaultColumnEntry<PraesentationStatistikSearchResult> {
  private static final long serialVersionUID = 1L;

  public PraesentationStatistikGenerierungZeitstempelColumn(String id, Messages messages, String headerKey, ColumnType type, Function<PraesentationStatistikSearchResult, Object> getter, Object... headerParams) {
    super(id, messages, headerKey, type, getter, headerParams);
  }

  @Override
  public boolean isIconPresent() {
    return true;
  }

  @Override
  public boolean isIconRendered(PraesentationStatistikSearchResult entity) {
    return super.isIconRendered(entity) || findeLetztenEintrag(entity.getStatistikEntries()).isError();
  }

  @Nullable
  @Override
  public String getIcon(PraesentationStatistikSearchResult entity) {
    if (findeLetztenEintrag(entity.getStatistikEntries()).isError()) {
      return "fa fa-exclamation-triangle";
    }
    return super.getIcon(entity);
  }

}
