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

import java.util.Arrays;

import de.ivu.elect.jee.entity.Entity;

public class PersonenRegisterCacheRequest {

  private Object[] parameters;

  public PersonenRegisterCacheRequest(Object... parametersCall) {
    if (parametersCall == null) {
      this.parameters = new Object[0];
    } else {
      this.parameters = new Object[parametersCall.length];
      for (int i = 0; i < parametersCall.length; i++) {
        Object p = parametersCall[i];
        if (p instanceof Entity) {
          this.parameters[i] = ((Entity<?, ?>) p).getPk(); // Keine Entitäten im Cache ablegen
        } else {
          this.parameters[i] = p;
        }
      }
    }
  }

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

    PersonenRegisterCacheRequest that = (PersonenRegisterCacheRequest) o;

    // Probably incorrect - comparing Object[] arrays with Arrays.equals
    return Arrays.equals(parameters, that.parameters);
  }

  @Override
  public int hashCode() {
    return Arrays.hashCode(parameters);
  }
}
