
package de.ivu.elect.jee.exchange;

import de.ivu.elect.jee.faces.Messages;

public class ViolationMitBezug extends AbstractViolation {

  private static final long serialVersionUID = 1L;

  private final String bezug;

  private final AbstractViolation wrappedViolation;

  public ViolationMitBezug(String bezug, AbstractViolation wrappedViolation) {
    super(wrappedViolation.getViolationLevel());

    this.bezug = bezug;

    this.wrappedViolation = wrappedViolation;
  }

  public String getBezug() {
    return bezug;
  }

  @Override
  public String getMessageKey() {
    return wrappedViolation.getMessageKey();
  }

  @Override
  public Object[] getMessageParameters(Messages messages) {
    return wrappedViolation.getMessageParameters(messages);
  }

  @Override
  protected String createDefaultMessage() {
    StringBuilder builder = new StringBuilder();

    builder.append(wrappedViolation.createDefaultMessage());
    builder.append(" - bezug=");
    builder.append(getBezug());

    return builder.toString();
  }

  @Override
  public String getMessage(Messages messages) {
    StringBuilder builder = new StringBuilder();

    if (getBezug() != null) {
      builder.append(getBezug()).append(": ");
    }

    builder.append(wrappedViolation.getMessage(messages));

    return builder.toString();
  }
}
