package de.ivu.elect.business.stimmzettel.entity;

import java.io.Serializable;

import de.ivu.elect.jee.faces.Messages;
import de.ivu.elect.jee.presentation.status.OutputSeverity;

public class StimmzettelErfassungValidationEntry implements Serializable {
  private static final long serialVersionUID = 1L;

  public static final StimmzettelErfassungValidationEntry SUCCESS = new StimmzettelErfassungValidationEntry(OutputSeverity.SUCCESS, null, null);

  private final OutputSeverity outputSeverity;

  private final String msgKey;

  private final Serializable[] params;

  public StimmzettelErfassungValidationEntry kombiniere(StimmzettelErfassungValidationEntry other) {
    if (other.isValid()) {
      return this;
    }
    if (this.isError()) {
      return this;
    }
    if (other.isError()) {
      return other;
    }
    if (this.isValid()) {
      return other;
    }
    return this;
  }

  public static StimmzettelErfassungValidationEntry createSuccessEntry() {
    return SUCCESS;
  }
  public static StimmzettelErfassungValidationEntry createWarn(String msgKey, Serializable... params) {
    return new StimmzettelErfassungValidationEntry(OutputSeverity.WARN, msgKey, params);
  }
  public static StimmzettelErfassungValidationEntry createError(String msgKey, Serializable... params) {
    return new StimmzettelErfassungValidationEntry(OutputSeverity.ERROR, msgKey, params);
  }

  public static StimmzettelErfassungValidationEntry createInformation(String msgKey, Serializable... params) {
    return new StimmzettelErfassungValidationEntry(OutputSeverity.INFO, msgKey, params);
  }

  private StimmzettelErfassungValidationEntry(OutputSeverity outputSeverity, String msgKey, Serializable[] params) {
    this.outputSeverity = outputSeverity;
    this.msgKey = msgKey;
    this.params = params;
  }

  public boolean isValid() {
    return outputSeverity.isSuccess();
  }

  public String getMesssage(Messages messages) {
    return messages.getMessageForMessageKey(msgKey, (Object[]) params);
  }

  public OutputSeverity getOutputSeverity() {
    return outputSeverity;
  }

  public boolean isWarn() {
    return outputSeverity.isWarn();
  }
  public boolean isError() {
    return outputSeverity.isError();
  }
}
