package org.infinispan.test.integration.data;

import java.io.Serializable;

import org.infinispan.protostream.annotations.ProtoField;

import jakarta.persistence.Basic;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;

/**
 * @author Radim Vansa &lt;rvansa@redhat.com&gt;
 * @since 7.0
 */
@Entity
public class KeyValueEntity implements Serializable {
   @Id
   private String k; // key is reserved word in SQL

   @Basic
   private String value;

   public KeyValueEntity() {
   }

   public KeyValueEntity(String key, String value) {
      this.k = key;
      this.value = value;
   }

   @ProtoField(1)
   public String getK() {
      return k;
   }

   public void setK(String k) {
      this.k = k;
   }

   @ProtoField(2)
   public String getValue() {
      return value;
   }

   public void setValue(String value) {
      this.value = value;
   }

   @Override
   public int hashCode() {
      final int prime = 31;
      int result = 1;
      result = prime * result + ((k == null) ? 0 : k.hashCode());
      result = prime * result + ((value == null) ? 0 : value.hashCode());
      return result;
   }

   @Override
   public boolean equals(Object obj) {
      if (this == obj)
         return true;
      if (obj == null)
         return false;
      if (getClass() != obj.getClass())
         return false;
      KeyValueEntity other = (KeyValueEntity) obj;
      if (k == null) {
         if (other.k != null)
            return false;
      } else if (!k.equals(other.k))
         return false;
      if (value == null) {
         if (other.value != null)
            return false;
      } else if (!value.equals(other.value))
         return false;
      return true;
   }

   @Override
   public String toString() {
      return String.format("{key=%s, value=%s}", k, value);
   }
}
