package de.ivu.elect.jee.entity;

import java.util.Arrays;

public class EntityConstraintViolation {

  private final Entity entity;

  private final String propertyKey;

  private final EntityConstraintViolationType constraintViolationType;

  private final Object[] params;

  public EntityConstraintViolation(Entity entity, String propertyKey, EntityConstraintViolationType constraintViolationType, Object... params) {
    this.entity = entity;
    this.propertyKey = propertyKey;
    this.constraintViolationType = constraintViolationType;
    this.params = params;
  }

  public Entity getEntity() {
    return entity;
  }

  public String getPropertyKey() {
    return propertyKey;
  }

  public EntityConstraintViolationType getConstraintViolationType() {
    return constraintViolationType;
  }

  public Object[] getParams() {
    return params;
  }

  @Override
  public String toString() {
    return "EntityConstraintViolation{" +
        "entity=" + entity +
        ", propertyKey='" + propertyKey + '\'' +
        ", constraintViolationType=" + constraintViolationType +
        ", params=" + Arrays.toString(params) +
        '}';
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    EntityConstraintViolation that = (EntityConstraintViolation) o;

    if (!entity.equals(that.entity)) return false;
    if (!propertyKey.equals(that.propertyKey)) return false;
    return constraintViolationType == that.constraintViolationType;
  }

  @Override
  public int hashCode() {
    int result = entity.hashCode();
    result = 31 * result + propertyKey.hashCode();
    result = 31 * result + constraintViolationType.hashCode();
    return result;
  }
}
