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

import javax.annotation.Nullable;

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

public class EmailVorgangStatusColumn<E extends EmailVorgang> extends AbstractEmailVorgangColumn<E> {

  private static final long serialVersionUID = 1L;

  private final Icons icons;

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

    this.icons = icons;
  }

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

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

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

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

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

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