package com.oguerreiro.resilient.service.dto;

import java.io.Serializable;
import java.util.Objects;

import io.swagger.v3.oas.annotations.media.Schema;

/**
 * Base Resilient DTO. All DTO's must extend this class.
 * 
 * @param <ID> - the class type of the entity domain primary key
 */
public abstract class AbstractResilientDTO<ID extends Serializable> implements Serializable {

  private static final long serialVersionUID = 1L;

  private ID id;

  @Schema(description = "Record version for concurrency control.")
  private Integer version;

  public ID getId() {
    return id;
  }

  public void setId(ID id) {
    this.id = id;
  }

  public Integer getVersion() {
    return version;
  }

  public void setVersion(Integer version) {
    this.version = version;
  }

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

    AbstractResilientDTO<?> domainDTO = (AbstractResilientDTO<?>) o;
    if (this.id == null) {
      return false;
    }
    return Objects.equals(this.id, domainDTO.id);
  }

  @Override
  public int hashCode() {
    return Objects.hash(this.id);
  }
}
