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

import java.util.function.Function;

import javax.annotation.Nullable;

import de.ivu.elect.business.internet.entity.PraesentationUploadStatusEntry;
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;

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

  private final Function<PraesentationStatistikSearchResult, PraesentationUploadStatusEntry> statusFct;

  public PraesentationStatistikUploadZeitstempelColumn(String id, Messages messages, String headerKey, ColumnType type,
                                                       Function<PraesentationStatistikSearchResult, Object> getter,
                                                       Function<PraesentationStatistikSearchResult, PraesentationUploadStatusEntry> statusFct,
                                                       Object... headerParams) {
    super(id, messages, headerKey, type, getter, headerParams);
    this.statusFct = statusFct;
  }

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

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

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

}
