/*
 * Daytona
 * Daytona AI platform API Docs
 *
 * The version of the OpenAPI document: 1.0
 * Contact: support@daytona.com
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */


package io.daytona.api.client.model;

import java.util.Objects;
import com.google.gson.TypeAdapter;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import io.daytona.api.client.model.BuildInfo;
import io.daytona.api.client.model.SnapshotState;
import java.io.IOException;
import java.math.BigDecimal;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import io.daytona.api.client.JSON;

/**
 * SnapshotDto
 */
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.21.0")
public class SnapshotDto {
  public static final String SERIALIZED_NAME_ID = "id";
  @SerializedName(SERIALIZED_NAME_ID)
  @javax.annotation.Nonnull
  private String id;

  public static final String SERIALIZED_NAME_ORGANIZATION_ID = "organizationId";
  @SerializedName(SERIALIZED_NAME_ORGANIZATION_ID)
  @javax.annotation.Nullable
  private String organizationId;

  public static final String SERIALIZED_NAME_GENERAL = "general";
  @SerializedName(SERIALIZED_NAME_GENERAL)
  @javax.annotation.Nonnull
  private Boolean general;

  public static final String SERIALIZED_NAME_NAME = "name";
  @SerializedName(SERIALIZED_NAME_NAME)
  @javax.annotation.Nonnull
  private String name;

  public static final String SERIALIZED_NAME_IMAGE_NAME = "imageName";
  @SerializedName(SERIALIZED_NAME_IMAGE_NAME)
  @javax.annotation.Nullable
  private String imageName;

  public static final String SERIALIZED_NAME_STATE = "state";
  @SerializedName(SERIALIZED_NAME_STATE)
  @javax.annotation.Nonnull
  private SnapshotState state;

  public static final String SERIALIZED_NAME_SIZE = "size";
  @SerializedName(SERIALIZED_NAME_SIZE)
  @javax.annotation.Nullable
  private BigDecimal size;

  public static final String SERIALIZED_NAME_ENTRYPOINT = "entrypoint";
  @SerializedName(SERIALIZED_NAME_ENTRYPOINT)
  @javax.annotation.Nullable
  private List<String> entrypoint;

  public static final String SERIALIZED_NAME_CPU = "cpu";
  @SerializedName(SERIALIZED_NAME_CPU)
  @javax.annotation.Nonnull
  private BigDecimal cpu;

  public static final String SERIALIZED_NAME_GPU = "gpu";
  @SerializedName(SERIALIZED_NAME_GPU)
  @javax.annotation.Nonnull
  private BigDecimal gpu;

  public static final String SERIALIZED_NAME_MEM = "mem";
  @SerializedName(SERIALIZED_NAME_MEM)
  @javax.annotation.Nonnull
  private BigDecimal mem;

  public static final String SERIALIZED_NAME_DISK = "disk";
  @SerializedName(SERIALIZED_NAME_DISK)
  @javax.annotation.Nonnull
  private BigDecimal disk;

  public static final String SERIALIZED_NAME_ERROR_REASON = "errorReason";
  @SerializedName(SERIALIZED_NAME_ERROR_REASON)
  @javax.annotation.Nullable
  private String errorReason;

  public static final String SERIALIZED_NAME_CREATED_AT = "createdAt";
  @SerializedName(SERIALIZED_NAME_CREATED_AT)
  @javax.annotation.Nonnull
  private OffsetDateTime createdAt;

  public static final String SERIALIZED_NAME_UPDATED_AT = "updatedAt";
  @SerializedName(SERIALIZED_NAME_UPDATED_AT)
  @javax.annotation.Nonnull
  private OffsetDateTime updatedAt;

  public static final String SERIALIZED_NAME_LAST_USED_AT = "lastUsedAt";
  @SerializedName(SERIALIZED_NAME_LAST_USED_AT)
  @javax.annotation.Nullable
  private OffsetDateTime lastUsedAt;

  public static final String SERIALIZED_NAME_BUILD_INFO = "buildInfo";
  @SerializedName(SERIALIZED_NAME_BUILD_INFO)
  @javax.annotation.Nullable
  private BuildInfo buildInfo;

  public static final String SERIALIZED_NAME_REGION_IDS = "regionIds";
  @SerializedName(SERIALIZED_NAME_REGION_IDS)
  @javax.annotation.Nullable
  private List<String> regionIds = new ArrayList<>();

  public static final String SERIALIZED_NAME_INITIAL_RUNNER_ID = "initialRunnerId";
  @SerializedName(SERIALIZED_NAME_INITIAL_RUNNER_ID)
  @javax.annotation.Nullable
  private String initialRunnerId;

  public static final String SERIALIZED_NAME_REF = "ref";
  @SerializedName(SERIALIZED_NAME_REF)
  @javax.annotation.Nullable
  private String ref;

  public SnapshotDto() {
  }

  public SnapshotDto id(@javax.annotation.Nonnull String id) {
    this.id = id;
    return this;
  }

  /**
   * Get id
   * @return id
   */
  @javax.annotation.Nonnull
  public String getId() {
    return id;
  }

  public void setId(@javax.annotation.Nonnull String id) {
    this.id = id;
  }


  public SnapshotDto organizationId(@javax.annotation.Nullable String organizationId) {
    this.organizationId = organizationId;
    return this;
  }

  /**
   * Get organizationId
   * @return organizationId
   */
  @javax.annotation.Nullable
  public String getOrganizationId() {
    return organizationId;
  }

  public void setOrganizationId(@javax.annotation.Nullable String organizationId) {
    this.organizationId = organizationId;
  }


  public SnapshotDto general(@javax.annotation.Nonnull Boolean general) {
    this.general = general;
    return this;
  }

  /**
   * Get general
   * @return general
   */
  @javax.annotation.Nonnull
  public Boolean getGeneral() {
    return general;
  }

  public void setGeneral(@javax.annotation.Nonnull Boolean general) {
    this.general = general;
  }


  public SnapshotDto name(@javax.annotation.Nonnull String name) {
    this.name = name;
    return this;
  }

  /**
   * Get name
   * @return name
   */
  @javax.annotation.Nonnull
  public String getName() {
    return name;
  }

  public void setName(@javax.annotation.Nonnull String name) {
    this.name = name;
  }


  public SnapshotDto imageName(@javax.annotation.Nullable String imageName) {
    this.imageName = imageName;
    return this;
  }

  /**
   * Get imageName
   * @return imageName
   */
  @javax.annotation.Nullable
  public String getImageName() {
    return imageName;
  }

  public void setImageName(@javax.annotation.Nullable String imageName) {
    this.imageName = imageName;
  }


  public SnapshotDto state(@javax.annotation.Nonnull SnapshotState state) {
    this.state = state;
    return this;
  }

  /**
   * Get state
   * @return state
   */
  @javax.annotation.Nonnull
  public SnapshotState getState() {
    return state;
  }

  public void setState(@javax.annotation.Nonnull SnapshotState state) {
    this.state = state;
  }


  public SnapshotDto size(@javax.annotation.Nullable BigDecimal size) {
    this.size = size;
    return this;
  }

  /**
   * Get size
   * @return size
   */
  @javax.annotation.Nullable
  public BigDecimal getSize() {
    return size;
  }

  public void setSize(@javax.annotation.Nullable BigDecimal size) {
    this.size = size;
  }


  public SnapshotDto entrypoint(@javax.annotation.Nullable List<String> entrypoint) {
    this.entrypoint = entrypoint;
    return this;
  }

  public SnapshotDto addEntrypointItem(String entrypointItem) {
    if (this.entrypoint == null) {
      this.entrypoint = new ArrayList<>();
    }
    this.entrypoint.add(entrypointItem);
    return this;
  }

  /**
   * Get entrypoint
   * @return entrypoint
   */
  @javax.annotation.Nullable
  public List<String> getEntrypoint() {
    return entrypoint;
  }

  public void setEntrypoint(@javax.annotation.Nullable List<String> entrypoint) {
    this.entrypoint = entrypoint;
  }


  public SnapshotDto cpu(@javax.annotation.Nonnull BigDecimal cpu) {
    this.cpu = cpu;
    return this;
  }

  /**
   * Get cpu
   * @return cpu
   */
  @javax.annotation.Nonnull
  public BigDecimal getCpu() {
    return cpu;
  }

  public void setCpu(@javax.annotation.Nonnull BigDecimal cpu) {
    this.cpu = cpu;
  }


  public SnapshotDto gpu(@javax.annotation.Nonnull BigDecimal gpu) {
    this.gpu = gpu;
    return this;
  }

  /**
   * Get gpu
   * @return gpu
   */
  @javax.annotation.Nonnull
  public BigDecimal getGpu() {
    return gpu;
  }

  public void setGpu(@javax.annotation.Nonnull BigDecimal gpu) {
    this.gpu = gpu;
  }


  public SnapshotDto mem(@javax.annotation.Nonnull BigDecimal mem) {
    this.mem = mem;
    return this;
  }

  /**
   * Get mem
   * @return mem
   */
  @javax.annotation.Nonnull
  public BigDecimal getMem() {
    return mem;
  }

  public void setMem(@javax.annotation.Nonnull BigDecimal mem) {
    this.mem = mem;
  }


  public SnapshotDto disk(@javax.annotation.Nonnull BigDecimal disk) {
    this.disk = disk;
    return this;
  }

  /**
   * Get disk
   * @return disk
   */
  @javax.annotation.Nonnull
  public BigDecimal getDisk() {
    return disk;
  }

  public void setDisk(@javax.annotation.Nonnull BigDecimal disk) {
    this.disk = disk;
  }


  public SnapshotDto errorReason(@javax.annotation.Nullable String errorReason) {
    this.errorReason = errorReason;
    return this;
  }

  /**
   * Get errorReason
   * @return errorReason
   */
  @javax.annotation.Nullable
  public String getErrorReason() {
    return errorReason;
  }

  public void setErrorReason(@javax.annotation.Nullable String errorReason) {
    this.errorReason = errorReason;
  }


  public SnapshotDto createdAt(@javax.annotation.Nonnull OffsetDateTime createdAt) {
    this.createdAt = createdAt;
    return this;
  }

  /**
   * Get createdAt
   * @return createdAt
   */
  @javax.annotation.Nonnull
  public OffsetDateTime getCreatedAt() {
    return createdAt;
  }

  public void setCreatedAt(@javax.annotation.Nonnull OffsetDateTime createdAt) {
    this.createdAt = createdAt;
  }


  public SnapshotDto updatedAt(@javax.annotation.Nonnull OffsetDateTime updatedAt) {
    this.updatedAt = updatedAt;
    return this;
  }

  /**
   * Get updatedAt
   * @return updatedAt
   */
  @javax.annotation.Nonnull
  public OffsetDateTime getUpdatedAt() {
    return updatedAt;
  }

  public void setUpdatedAt(@javax.annotation.Nonnull OffsetDateTime updatedAt) {
    this.updatedAt = updatedAt;
  }


  public SnapshotDto lastUsedAt(@javax.annotation.Nullable OffsetDateTime lastUsedAt) {
    this.lastUsedAt = lastUsedAt;
    return this;
  }

  /**
   * Get lastUsedAt
   * @return lastUsedAt
   */
  @javax.annotation.Nullable
  public OffsetDateTime getLastUsedAt() {
    return lastUsedAt;
  }

  public void setLastUsedAt(@javax.annotation.Nullable OffsetDateTime lastUsedAt) {
    this.lastUsedAt = lastUsedAt;
  }


  public SnapshotDto buildInfo(@javax.annotation.Nullable BuildInfo buildInfo) {
    this.buildInfo = buildInfo;
    return this;
  }

  /**
   * Build information for the snapshot
   * @return buildInfo
   */
  @javax.annotation.Nullable
  public BuildInfo getBuildInfo() {
    return buildInfo;
  }

  public void setBuildInfo(@javax.annotation.Nullable BuildInfo buildInfo) {
    this.buildInfo = buildInfo;
  }


  public SnapshotDto regionIds(@javax.annotation.Nullable List<String> regionIds) {
    this.regionIds = regionIds;
    return this;
  }

  public SnapshotDto addRegionIdsItem(String regionIdsItem) {
    if (this.regionIds == null) {
      this.regionIds = new ArrayList<>();
    }
    this.regionIds.add(regionIdsItem);
    return this;
  }

  /**
   * IDs of regions where the snapshot is available
   * @return regionIds
   */
  @javax.annotation.Nullable
  public List<String> getRegionIds() {
    return regionIds;
  }

  public void setRegionIds(@javax.annotation.Nullable List<String> regionIds) {
    this.regionIds = regionIds;
  }


  public SnapshotDto initialRunnerId(@javax.annotation.Nullable String initialRunnerId) {
    this.initialRunnerId = initialRunnerId;
    return this;
  }

  /**
   * The initial runner ID of the snapshot
   * @return initialRunnerId
   */
  @javax.annotation.Nullable
  public String getInitialRunnerId() {
    return initialRunnerId;
  }

  public void setInitialRunnerId(@javax.annotation.Nullable String initialRunnerId) {
    this.initialRunnerId = initialRunnerId;
  }


  public SnapshotDto ref(@javax.annotation.Nullable String ref) {
    this.ref = ref;
    return this;
  }

  /**
   * The snapshot reference
   * @return ref
   */
  @javax.annotation.Nullable
  public String getRef() {
    return ref;
  }

  public void setRef(@javax.annotation.Nullable String ref) {
    this.ref = ref;
  }

  /**
   * A container for additional, undeclared properties.
   * This is a holder for any undeclared properties as specified with
   * the 'additionalProperties' keyword in the OAS document.
   */
  private Map<String, Object> additionalProperties;

  /**
   * Set the additional (undeclared) property with the specified name and value.
   * If the property does not already exist, create it otherwise replace it.
   *
   * @param key name of the property
   * @param value value of the property
   * @return the SnapshotDto instance itself
   */
  public SnapshotDto putAdditionalProperty(String key, Object value) {
    if (this.additionalProperties == null) {
        this.additionalProperties = new HashMap<String, Object>();
    }
    this.additionalProperties.put(key, value);
    return this;
  }

  /**
   * Return the additional (undeclared) property.
   *
   * @return a map of objects
   */
  public Map<String, Object> getAdditionalProperties() {
    return additionalProperties;
  }

  /**
   * Return the additional (undeclared) property with the specified name.
   *
   * @param key name of the property
   * @return an object
   */
  public Object getAdditionalProperty(String key) {
    if (this.additionalProperties == null) {
        return null;
    }
    return this.additionalProperties.get(key);
  }


  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    SnapshotDto snapshotDto = (SnapshotDto) o;
    return Objects.equals(this.id, snapshotDto.id) &&
        Objects.equals(this.organizationId, snapshotDto.organizationId) &&
        Objects.equals(this.general, snapshotDto.general) &&
        Objects.equals(this.name, snapshotDto.name) &&
        Objects.equals(this.imageName, snapshotDto.imageName) &&
        Objects.equals(this.state, snapshotDto.state) &&
        Objects.equals(this.size, snapshotDto.size) &&
        Objects.equals(this.entrypoint, snapshotDto.entrypoint) &&
        Objects.equals(this.cpu, snapshotDto.cpu) &&
        Objects.equals(this.gpu, snapshotDto.gpu) &&
        Objects.equals(this.mem, snapshotDto.mem) &&
        Objects.equals(this.disk, snapshotDto.disk) &&
        Objects.equals(this.errorReason, snapshotDto.errorReason) &&
        Objects.equals(this.createdAt, snapshotDto.createdAt) &&
        Objects.equals(this.updatedAt, snapshotDto.updatedAt) &&
        Objects.equals(this.lastUsedAt, snapshotDto.lastUsedAt) &&
        Objects.equals(this.buildInfo, snapshotDto.buildInfo) &&
        Objects.equals(this.regionIds, snapshotDto.regionIds) &&
        Objects.equals(this.initialRunnerId, snapshotDto.initialRunnerId) &&
        Objects.equals(this.ref, snapshotDto.ref)&&
        Objects.equals(this.additionalProperties, snapshotDto.additionalProperties);
  }

  @Override
  public int hashCode() {
    return Objects.hash(id, organizationId, general, name, imageName, state, size, entrypoint, cpu, gpu, mem, disk, errorReason, createdAt, updatedAt, lastUsedAt, buildInfo, regionIds, initialRunnerId, ref, additionalProperties);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class SnapshotDto {\n");
    sb.append("    id: ").append(toIndentedString(id)).append("\n");
    sb.append("    organizationId: ").append(toIndentedString(organizationId)).append("\n");
    sb.append("    general: ").append(toIndentedString(general)).append("\n");
    sb.append("    name: ").append(toIndentedString(name)).append("\n");
    sb.append("    imageName: ").append(toIndentedString(imageName)).append("\n");
    sb.append("    state: ").append(toIndentedString(state)).append("\n");
    sb.append("    size: ").append(toIndentedString(size)).append("\n");
    sb.append("    entrypoint: ").append(toIndentedString(entrypoint)).append("\n");
    sb.append("    cpu: ").append(toIndentedString(cpu)).append("\n");
    sb.append("    gpu: ").append(toIndentedString(gpu)).append("\n");
    sb.append("    mem: ").append(toIndentedString(mem)).append("\n");
    sb.append("    disk: ").append(toIndentedString(disk)).append("\n");
    sb.append("    errorReason: ").append(toIndentedString(errorReason)).append("\n");
    sb.append("    createdAt: ").append(toIndentedString(createdAt)).append("\n");
    sb.append("    updatedAt: ").append(toIndentedString(updatedAt)).append("\n");
    sb.append("    lastUsedAt: ").append(toIndentedString(lastUsedAt)).append("\n");
    sb.append("    buildInfo: ").append(toIndentedString(buildInfo)).append("\n");
    sb.append("    regionIds: ").append(toIndentedString(regionIds)).append("\n");
    sb.append("    initialRunnerId: ").append(toIndentedString(initialRunnerId)).append("\n");
    sb.append("    ref: ").append(toIndentedString(ref)).append("\n");
    sb.append("    additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n");
    sb.append("}");
    return sb.toString();
  }

  /**
   * Convert the given object to string with each line indented by 4 spaces
   * (except the first line).
   */
  private String toIndentedString(Object o) {
    return o == null ? "null" : o.toString().replace("\n", "\n    ");
  }


  public static HashSet<String> openapiFields;
  public static HashSet<String> openapiRequiredFields;

  static {
    // a set of all properties/fields (JSON key names)
    openapiFields = new HashSet<String>(Arrays.asList("id", "organizationId", "general", "name", "imageName", "state", "size", "entrypoint", "cpu", "gpu", "mem", "disk", "errorReason", "createdAt", "updatedAt", "lastUsedAt", "buildInfo", "regionIds", "initialRunnerId", "ref"));

    // a set of required properties/fields (JSON key names)
    openapiRequiredFields = new HashSet<String>(Arrays.asList("id", "general", "name", "state", "size", "entrypoint", "cpu", "gpu", "mem", "disk", "errorReason", "createdAt", "updatedAt", "lastUsedAt"));
  }

  /**
   * Validates the JSON Element and throws an exception if issues found
   *
   * @param jsonElement JSON Element
   * @throws IOException if the JSON Element is invalid with respect to SnapshotDto
   */
  public static void validateJsonElement(JsonElement jsonElement) throws IOException {
      if (jsonElement == null) {
        if (!SnapshotDto.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null
          throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "The required field(s) %s in SnapshotDto is not found in the empty JSON string", SnapshotDto.openapiRequiredFields.toString()));
        }
      }

      // check to make sure all required properties/fields are present in the JSON string
      for (String requiredField : SnapshotDto.openapiRequiredFields) {
        if (jsonElement.getAsJsonObject().get(requiredField) == null) {
          throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "The required field `%s` is not found in the JSON string: %s", requiredField, jsonElement.toString()));
        }
      }
        JsonObject jsonObj = jsonElement.getAsJsonObject();
      if (!jsonObj.get("id").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `id` to be a primitive type in the JSON string but got `%s`", jsonObj.get("id").toString()));
      }
      if ((jsonObj.get("organizationId") != null && !jsonObj.get("organizationId").isJsonNull()) && !jsonObj.get("organizationId").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `organizationId` to be a primitive type in the JSON string but got `%s`", jsonObj.get("organizationId").toString()));
      }
      if (!jsonObj.get("name").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `name` to be a primitive type in the JSON string but got `%s`", jsonObj.get("name").toString()));
      }
      if ((jsonObj.get("imageName") != null && !jsonObj.get("imageName").isJsonNull()) && !jsonObj.get("imageName").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `imageName` to be a primitive type in the JSON string but got `%s`", jsonObj.get("imageName").toString()));
      }
      // validate the required field `state`
      SnapshotState.validateJsonElement(jsonObj.get("state"));
      // ensure the required json array is present
      if (jsonObj.get("entrypoint") == null) {
        throw new IllegalArgumentException("Expected the field `linkedContent` to be an array in the JSON string but got `null`");
      } else if (!jsonObj.get("entrypoint").isJsonArray() && !jsonObj.get("entrypoint").isJsonNull()) {
        throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `entrypoint` to be an array in the JSON string but got `%s`", jsonObj.get("entrypoint").toString()));
      }
      if ((jsonObj.get("errorReason") != null && !jsonObj.get("errorReason").isJsonNull()) && !jsonObj.get("errorReason").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `errorReason` to be a primitive type in the JSON string but got `%s`", jsonObj.get("errorReason").toString()));
      }
      // validate the optional field `buildInfo`
      if (jsonObj.get("buildInfo") != null && !jsonObj.get("buildInfo").isJsonNull()) {
        BuildInfo.validateJsonElement(jsonObj.get("buildInfo"));
      }
      // ensure the optional json data is an array if present
      if (jsonObj.get("regionIds") != null && !jsonObj.get("regionIds").isJsonNull() && !jsonObj.get("regionIds").isJsonArray()) {
        throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `regionIds` to be an array in the JSON string but got `%s`", jsonObj.get("regionIds").toString()));
      }
      if ((jsonObj.get("initialRunnerId") != null && !jsonObj.get("initialRunnerId").isJsonNull()) && !jsonObj.get("initialRunnerId").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `initialRunnerId` to be a primitive type in the JSON string but got `%s`", jsonObj.get("initialRunnerId").toString()));
      }
      if ((jsonObj.get("ref") != null && !jsonObj.get("ref").isJsonNull()) && !jsonObj.get("ref").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `ref` to be a primitive type in the JSON string but got `%s`", jsonObj.get("ref").toString()));
      }
  }

  public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
    @SuppressWarnings("unchecked")
    @Override
    public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
       if (!SnapshotDto.class.isAssignableFrom(type.getRawType())) {
         return null; // this class only serializes 'SnapshotDto' and its subtypes
       }
       final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
       final TypeAdapter<SnapshotDto> thisAdapter
                        = gson.getDelegateAdapter(this, TypeToken.get(SnapshotDto.class));

       return (TypeAdapter<T>) new TypeAdapter<SnapshotDto>() {
           @Override
           public void write(JsonWriter out, SnapshotDto value) throws IOException {
             JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
             obj.remove("additionalProperties");
             // serialize additional properties
             if (value.getAdditionalProperties() != null) {
               for (Map.Entry<String, Object> entry : value.getAdditionalProperties().entrySet()) {
                 if (entry.getValue() instanceof String)
                   obj.addProperty(entry.getKey(), (String) entry.getValue());
                 else if (entry.getValue() instanceof Number)
                   obj.addProperty(entry.getKey(), (Number) entry.getValue());
                 else if (entry.getValue() instanceof Boolean)
                   obj.addProperty(entry.getKey(), (Boolean) entry.getValue());
                 else if (entry.getValue() instanceof Character)
                   obj.addProperty(entry.getKey(), (Character) entry.getValue());
                 else {
                   JsonElement jsonElement = gson.toJsonTree(entry.getValue());
                   if (jsonElement.isJsonArray()) {
                     obj.add(entry.getKey(), jsonElement.getAsJsonArray());
                   } else {
                     obj.add(entry.getKey(), jsonElement.getAsJsonObject());
                   }
                 }
               }
             }
             elementAdapter.write(out, obj);
           }

           @Override
           public SnapshotDto read(JsonReader in) throws IOException {
             JsonElement jsonElement = elementAdapter.read(in);
             validateJsonElement(jsonElement);
             JsonObject jsonObj = jsonElement.getAsJsonObject();
             // store additional fields in the deserialized instance
             SnapshotDto instance = thisAdapter.fromJsonTree(jsonObj);
             for (Map.Entry<String, JsonElement> entry : jsonObj.entrySet()) {
               if (!openapiFields.contains(entry.getKey())) {
                 if (entry.getValue().isJsonPrimitive()) { // primitive type
                   if (entry.getValue().getAsJsonPrimitive().isString())
                     instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsString());
                   else if (entry.getValue().getAsJsonPrimitive().isNumber())
                     instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsNumber());
                   else if (entry.getValue().getAsJsonPrimitive().isBoolean())
                     instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsBoolean());
                   else
                     throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "The field `%s` has unknown primitive type. Value: %s", entry.getKey(), entry.getValue().toString()));
                 } else if (entry.getValue().isJsonArray()) {
                     instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), List.class));
                 } else { // JSON object
                     instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), HashMap.class));
                 }
               }
             }
             return instance;
           }

       }.nullSafe();
    }
  }

  /**
   * Create an instance of SnapshotDto given an JSON string
   *
   * @param jsonString JSON string
   * @return An instance of SnapshotDto
   * @throws IOException if the JSON string is invalid with respect to SnapshotDto
   */
  public static SnapshotDto fromJson(String jsonString) throws IOException {
    return JSON.getGson().fromJson(jsonString, SnapshotDto.class);
  }

  /**
   * Convert an instance of SnapshotDto to an JSON string
   *
   * @return JSON string
   */
  public String toJson() {
    return JSON.getGson().toJson(this);
  }
}

