
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;

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

    this.icons = icons;
  }

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

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

  @Nullable
  @Override
  public String getIcon(E email) {
    if (email == null || email.getStatus() == null) {
      return null;
    }

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

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

    return getMessage(email.getStatus());
  }
}
