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

import javax.annotation.Nullable;

import de.ivu.elect.business.email.entity.AbstractEmail;
import de.ivu.elect.business.email.entity.Email;
import de.ivu.elect.jee.faces.Messages;
import de.ivu.elect.jee.presentation.Icons;
import de.ivu.elect.jee.presentation.dynamictable.ColumnType;

public class EmailAnhaengeColumn<E extends Email> extends AbstractEmailColumn<E> {

  private static final long serialVersionUID = 1L;

  private final Icons icons;

  protected EmailAnhaengeColumn(Messages messages, Icons icons) {
    super("Email-Anhaenge", messages, "email.column.anhaenge", ColumnType.STRING, Email::getAnhaengeAsString);

    this.icons = icons;
  }

  @Nullable
  @Override
  public Object getDisplayValue(E entity) {
    return "";
  }

  @Override
  public String getTooltip(E entity) {
    if (entity == null) {
      return null;
    }

    return entity.getAnhaengeAsString().replaceAll(AbstractEmail.ANHANG_SEPARATOR, TOOLTIP_LINE_SEPARATOR);
  }

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

  @Override
  public boolean isIconRendered(E entity) {
    return getIcon(entity) != null;
  }

  @Nullable
  @Override
  public String getIcon(E entity) {
    if (entity == null || !entity.hasAnhaenge()) {
      return null;
    }

    return icons.getIconEmailAnhang();
  }
}
