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

import javax.annotation.Nullable;

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 EmailStatusColumn<E extends Email> extends AbstractEmailColumn<E> {

  private static final long serialVersionUID = 1L;

  private final Icons icons;

  protected EmailStatusColumn(Messages messages, Icons icons) {
    super("Email-Status", messages, "email.column.status", ColumnType.ENUM, Email::getStatus);

    this.icons = icons;
  }

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

    return getMessage(entity.getStatus());
  }

  @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) {
      return null;
    }

    return entity.getStatus().getIcon(icons);
  }
}
