/*
 * 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.CreateBuildInfo;
import io.daytona.api.client.model.SandboxVolume;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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;

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

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

  public static final String SERIALIZED_NAME_ENV = "env";
  @SerializedName(SERIALIZED_NAME_ENV)
  @javax.annotation.Nullable
  private Map<String, String> env = new HashMap<>();

  public static final String SERIALIZED_NAME_LABELS = "labels";
  @SerializedName(SERIALIZED_NAME_LABELS)
  @javax.annotation.Nullable
  private Map<String, String> labels = new HashMap<>();

  public static final String SERIALIZED_NAME_PUBLIC = "public";
  @SerializedName(SERIALIZED_NAME_PUBLIC)
  @javax.annotation.Nullable
  private Boolean _public;

  /**
   * The workspace class type
   */
  @JsonAdapter(PropertyClassEnum.Adapter.class)
  public enum PropertyClassEnum {
    SMALL("small"),
    
    MEDIUM("medium"),
    
    LARGE("large"),
    
    UNKNOWN_DEFAULT_OPEN_API("unknown_default_open_api");

    private String value;

    PropertyClassEnum(String value) {
      this.value = value;
    }

    public String getValue() {
      return value;
    }

    @Override
    public String toString() {
      return String.valueOf(value);
    }

    public static PropertyClassEnum fromValue(String value) {
      for (PropertyClassEnum b : PropertyClassEnum.values()) {
        if (b.value.equals(value)) {
          return b;
        }
      }
      return UNKNOWN_DEFAULT_OPEN_API;
    }

    public static class Adapter extends TypeAdapter<PropertyClassEnum> {
      @Override
      public void write(final JsonWriter jsonWriter, final PropertyClassEnum enumeration) throws IOException {
        jsonWriter.value(enumeration.getValue());
      }

      @Override
      public PropertyClassEnum read(final JsonReader jsonReader) throws IOException {
        String value =  jsonReader.nextString();
        return PropertyClassEnum.fromValue(value);
      }
    }

    public static void validateJsonElement(JsonElement jsonElement) throws IOException {
      String value = jsonElement.getAsString();
      PropertyClassEnum.fromValue(value);
    }
  }

  public static final String SERIALIZED_NAME_PROPERTY_CLASS = "class";
  @SerializedName(SERIALIZED_NAME_PROPERTY_CLASS)
  @javax.annotation.Nullable
  private PropertyClassEnum propertyClass;

  /**
   * The target (region) where the workspace will be created
   */
  @JsonAdapter(TargetEnum.Adapter.class)
  public enum TargetEnum {
    EU("eu"),
    
    US("us"),
    
    ASIA("asia"),
    
    UNKNOWN_DEFAULT_OPEN_API("unknown_default_open_api");

    private String value;

    TargetEnum(String value) {
      this.value = value;
    }

    public String getValue() {
      return value;
    }

    @Override
    public String toString() {
      return String.valueOf(value);
    }

    public static TargetEnum fromValue(String value) {
      for (TargetEnum b : TargetEnum.values()) {
        if (b.value.equals(value)) {
          return b;
        }
      }
      return UNKNOWN_DEFAULT_OPEN_API;
    }

    public static class Adapter extends TypeAdapter<TargetEnum> {
      @Override
      public void write(final JsonWriter jsonWriter, final TargetEnum enumeration) throws IOException {
        jsonWriter.value(enumeration.getValue());
      }

      @Override
      public TargetEnum read(final JsonReader jsonReader) throws IOException {
        String value =  jsonReader.nextString();
        return TargetEnum.fromValue(value);
      }
    }

    public static void validateJsonElement(JsonElement jsonElement) throws IOException {
      String value = jsonElement.getAsString();
      TargetEnum.fromValue(value);
    }
  }

  public static final String SERIALIZED_NAME_TARGET = "target";
  @SerializedName(SERIALIZED_NAME_TARGET)
  @javax.annotation.Nullable
  private TargetEnum target;

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

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

  public static final String SERIALIZED_NAME_MEMORY = "memory";
  @SerializedName(SERIALIZED_NAME_MEMORY)
  @javax.annotation.Nullable
  private Integer memory;

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

  public static final String SERIALIZED_NAME_AUTO_STOP_INTERVAL = "autoStopInterval";
  @SerializedName(SERIALIZED_NAME_AUTO_STOP_INTERVAL)
  @javax.annotation.Nullable
  private Integer autoStopInterval;

  public static final String SERIALIZED_NAME_AUTO_ARCHIVE_INTERVAL = "autoArchiveInterval";
  @SerializedName(SERIALIZED_NAME_AUTO_ARCHIVE_INTERVAL)
  @javax.annotation.Nullable
  private Integer autoArchiveInterval;

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

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

  public CreateWorkspace() {
  }

  public CreateWorkspace image(@javax.annotation.Nullable String image) {
    this.image = image;
    return this;
  }

  /**
   * The image used for the workspace
   * @return image
   */
  @javax.annotation.Nullable
  public String getImage() {
    return image;
  }

  public void setImage(@javax.annotation.Nullable String image) {
    this.image = image;
  }


  public CreateWorkspace user(@javax.annotation.Nullable String user) {
    this.user = user;
    return this;
  }

  /**
   * The user associated with the project
   * @return user
   */
  @javax.annotation.Nullable
  public String getUser() {
    return user;
  }

  public void setUser(@javax.annotation.Nullable String user) {
    this.user = user;
  }


  public CreateWorkspace env(@javax.annotation.Nullable Map<String, String> env) {
    this.env = env;
    return this;
  }

  public CreateWorkspace putEnvItem(String key, String envItem) {
    if (this.env == null) {
      this.env = new HashMap<>();
    }
    this.env.put(key, envItem);
    return this;
  }

  /**
   * Environment variables for the workspace
   * @return env
   */
  @javax.annotation.Nullable
  public Map<String, String> getEnv() {
    return env;
  }

  public void setEnv(@javax.annotation.Nullable Map<String, String> env) {
    this.env = env;
  }


  public CreateWorkspace labels(@javax.annotation.Nullable Map<String, String> labels) {
    this.labels = labels;
    return this;
  }

  public CreateWorkspace putLabelsItem(String key, String labelsItem) {
    if (this.labels == null) {
      this.labels = new HashMap<>();
    }
    this.labels.put(key, labelsItem);
    return this;
  }

  /**
   * Labels for the workspace
   * @return labels
   */
  @javax.annotation.Nullable
  public Map<String, String> getLabels() {
    return labels;
  }

  public void setLabels(@javax.annotation.Nullable Map<String, String> labels) {
    this.labels = labels;
  }


  public CreateWorkspace _public(@javax.annotation.Nullable Boolean _public) {
    this._public = _public;
    return this;
  }

  /**
   * Whether the workspace http preview is publicly accessible
   * @return _public
   */
  @javax.annotation.Nullable
  public Boolean getPublic() {
    return _public;
  }

  public void setPublic(@javax.annotation.Nullable Boolean _public) {
    this._public = _public;
  }


  public CreateWorkspace propertyClass(@javax.annotation.Nullable PropertyClassEnum propertyClass) {
    this.propertyClass = propertyClass;
    return this;
  }

  /**
   * The workspace class type
   * @return propertyClass
   */
  @javax.annotation.Nullable
  public PropertyClassEnum getPropertyClass() {
    return propertyClass;
  }

  public void setPropertyClass(@javax.annotation.Nullable PropertyClassEnum propertyClass) {
    this.propertyClass = propertyClass;
  }


  public CreateWorkspace target(@javax.annotation.Nullable TargetEnum target) {
    this.target = target;
    return this;
  }

  /**
   * The target (region) where the workspace will be created
   * @return target
   */
  @javax.annotation.Nullable
  public TargetEnum getTarget() {
    return target;
  }

  public void setTarget(@javax.annotation.Nullable TargetEnum target) {
    this.target = target;
  }


  public CreateWorkspace cpu(@javax.annotation.Nullable Integer cpu) {
    this.cpu = cpu;
    return this;
  }

  /**
   * CPU cores allocated to the workspace
   * @return cpu
   */
  @javax.annotation.Nullable
  public Integer getCpu() {
    return cpu;
  }

  public void setCpu(@javax.annotation.Nullable Integer cpu) {
    this.cpu = cpu;
  }


  public CreateWorkspace gpu(@javax.annotation.Nullable Integer gpu) {
    this.gpu = gpu;
    return this;
  }

  /**
   * GPU units allocated to the workspace
   * @return gpu
   */
  @javax.annotation.Nullable
  public Integer getGpu() {
    return gpu;
  }

  public void setGpu(@javax.annotation.Nullable Integer gpu) {
    this.gpu = gpu;
  }


  public CreateWorkspace memory(@javax.annotation.Nullable Integer memory) {
    this.memory = memory;
    return this;
  }

  /**
   * Memory allocated to the workspace in GB
   * @return memory
   */
  @javax.annotation.Nullable
  public Integer getMemory() {
    return memory;
  }

  public void setMemory(@javax.annotation.Nullable Integer memory) {
    this.memory = memory;
  }


  public CreateWorkspace disk(@javax.annotation.Nullable Integer disk) {
    this.disk = disk;
    return this;
  }

  /**
   * Disk space allocated to the workspace in GB
   * @return disk
   */
  @javax.annotation.Nullable
  public Integer getDisk() {
    return disk;
  }

  public void setDisk(@javax.annotation.Nullable Integer disk) {
    this.disk = disk;
  }


  public CreateWorkspace autoStopInterval(@javax.annotation.Nullable Integer autoStopInterval) {
    this.autoStopInterval = autoStopInterval;
    return this;
  }

  /**
   * Auto-stop interval in minutes (0 means disabled)
   * @return autoStopInterval
   */
  @javax.annotation.Nullable
  public Integer getAutoStopInterval() {
    return autoStopInterval;
  }

  public void setAutoStopInterval(@javax.annotation.Nullable Integer autoStopInterval) {
    this.autoStopInterval = autoStopInterval;
  }


  public CreateWorkspace autoArchiveInterval(@javax.annotation.Nullable Integer autoArchiveInterval) {
    this.autoArchiveInterval = autoArchiveInterval;
    return this;
  }

  /**
   * Auto-archive interval in minutes (0 means the maximum interval will be used)
   * @return autoArchiveInterval
   */
  @javax.annotation.Nullable
  public Integer getAutoArchiveInterval() {
    return autoArchiveInterval;
  }

  public void setAutoArchiveInterval(@javax.annotation.Nullable Integer autoArchiveInterval) {
    this.autoArchiveInterval = autoArchiveInterval;
  }


  public CreateWorkspace volumes(@javax.annotation.Nullable List<SandboxVolume> volumes) {
    this.volumes = volumes;
    return this;
  }

  public CreateWorkspace addVolumesItem(SandboxVolume volumesItem) {
    if (this.volumes == null) {
      this.volumes = new ArrayList<>();
    }
    this.volumes.add(volumesItem);
    return this;
  }

  /**
   * Array of volumes to attach to the workspace
   * @return volumes
   */
  @javax.annotation.Nullable
  public List<SandboxVolume> getVolumes() {
    return volumes;
  }

  public void setVolumes(@javax.annotation.Nullable List<SandboxVolume> volumes) {
    this.volumes = volumes;
  }


  public CreateWorkspace buildInfo(@javax.annotation.Nullable CreateBuildInfo buildInfo) {
    this.buildInfo = buildInfo;
    return this;
  }

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

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

  /**
   * 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 CreateWorkspace instance itself
   */
  public CreateWorkspace 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;
    }
    CreateWorkspace createWorkspace = (CreateWorkspace) o;
    return Objects.equals(this.image, createWorkspace.image) &&
        Objects.equals(this.user, createWorkspace.user) &&
        Objects.equals(this.env, createWorkspace.env) &&
        Objects.equals(this.labels, createWorkspace.labels) &&
        Objects.equals(this._public, createWorkspace._public) &&
        Objects.equals(this.propertyClass, createWorkspace.propertyClass) &&
        Objects.equals(this.target, createWorkspace.target) &&
        Objects.equals(this.cpu, createWorkspace.cpu) &&
        Objects.equals(this.gpu, createWorkspace.gpu) &&
        Objects.equals(this.memory, createWorkspace.memory) &&
        Objects.equals(this.disk, createWorkspace.disk) &&
        Objects.equals(this.autoStopInterval, createWorkspace.autoStopInterval) &&
        Objects.equals(this.autoArchiveInterval, createWorkspace.autoArchiveInterval) &&
        Objects.equals(this.volumes, createWorkspace.volumes) &&
        Objects.equals(this.buildInfo, createWorkspace.buildInfo)&&
        Objects.equals(this.additionalProperties, createWorkspace.additionalProperties);
  }

  @Override
  public int hashCode() {
    return Objects.hash(image, user, env, labels, _public, propertyClass, target, cpu, gpu, memory, disk, autoStopInterval, autoArchiveInterval, volumes, buildInfo, additionalProperties);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class CreateWorkspace {\n");
    sb.append("    image: ").append(toIndentedString(image)).append("\n");
    sb.append("    user: ").append(toIndentedString(user)).append("\n");
    sb.append("    env: ").append(toIndentedString(env)).append("\n");
    sb.append("    labels: ").append(toIndentedString(labels)).append("\n");
    sb.append("    _public: ").append(toIndentedString(_public)).append("\n");
    sb.append("    propertyClass: ").append(toIndentedString(propertyClass)).append("\n");
    sb.append("    target: ").append(toIndentedString(target)).append("\n");
    sb.append("    cpu: ").append(toIndentedString(cpu)).append("\n");
    sb.append("    gpu: ").append(toIndentedString(gpu)).append("\n");
    sb.append("    memory: ").append(toIndentedString(memory)).append("\n");
    sb.append("    disk: ").append(toIndentedString(disk)).append("\n");
    sb.append("    autoStopInterval: ").append(toIndentedString(autoStopInterval)).append("\n");
    sb.append("    autoArchiveInterval: ").append(toIndentedString(autoArchiveInterval)).append("\n");
    sb.append("    volumes: ").append(toIndentedString(volumes)).append("\n");
    sb.append("    buildInfo: ").append(toIndentedString(buildInfo)).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("image", "user", "env", "labels", "public", "class", "target", "cpu", "gpu", "memory", "disk", "autoStopInterval", "autoArchiveInterval", "volumes", "buildInfo"));

    // a set of required properties/fields (JSON key names)
    openapiRequiredFields = new HashSet<String>(0);
  }

  /**
   * 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 CreateWorkspace
   */
  public static void validateJsonElement(JsonElement jsonElement) throws IOException {
      if (jsonElement == null) {
        if (!CreateWorkspace.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 CreateWorkspace is not found in the empty JSON string", CreateWorkspace.openapiRequiredFields.toString()));
        }
      }
        JsonObject jsonObj = jsonElement.getAsJsonObject();
      if ((jsonObj.get("image") != null && !jsonObj.get("image").isJsonNull()) && !jsonObj.get("image").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `image` to be a primitive type in the JSON string but got `%s`", jsonObj.get("image").toString()));
      }
      if ((jsonObj.get("user") != null && !jsonObj.get("user").isJsonNull()) && !jsonObj.get("user").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `user` to be a primitive type in the JSON string but got `%s`", jsonObj.get("user").toString()));
      }
      if ((jsonObj.get("class") != null && !jsonObj.get("class").isJsonNull()) && !jsonObj.get("class").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `class` to be a primitive type in the JSON string but got `%s`", jsonObj.get("class").toString()));
      }
      // validate the optional field `class`
      if (jsonObj.get("class") != null && !jsonObj.get("class").isJsonNull()) {
        PropertyClassEnum.validateJsonElement(jsonObj.get("class"));
      }
      if ((jsonObj.get("target") != null && !jsonObj.get("target").isJsonNull()) && !jsonObj.get("target").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `target` to be a primitive type in the JSON string but got `%s`", jsonObj.get("target").toString()));
      }
      // validate the optional field `target`
      if (jsonObj.get("target") != null && !jsonObj.get("target").isJsonNull()) {
        TargetEnum.validateJsonElement(jsonObj.get("target"));
      }
      if (jsonObj.get("volumes") != null && !jsonObj.get("volumes").isJsonNull()) {
        JsonArray jsonArrayvolumes = jsonObj.getAsJsonArray("volumes");
        if (jsonArrayvolumes != null) {
          // ensure the json data is an array
          if (!jsonObj.get("volumes").isJsonArray()) {
            throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `volumes` to be an array in the JSON string but got `%s`", jsonObj.get("volumes").toString()));
          }

          // validate the optional field `volumes` (array)
          for (int i = 0; i < jsonArrayvolumes.size(); i++) {
            SandboxVolume.validateJsonElement(jsonArrayvolumes.get(i));
          };
        }
      }
      // validate the optional field `buildInfo`
      if (jsonObj.get("buildInfo") != null && !jsonObj.get("buildInfo").isJsonNull()) {
        CreateBuildInfo.validateJsonElement(jsonObj.get("buildInfo"));
      }
  }

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

       return (TypeAdapter<T>) new TypeAdapter<CreateWorkspace>() {
           @Override
           public void write(JsonWriter out, CreateWorkspace 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 CreateWorkspace read(JsonReader in) throws IOException {
             JsonElement jsonElement = elementAdapter.read(in);
             validateJsonElement(jsonElement);
             JsonObject jsonObj = jsonElement.getAsJsonObject();
             // store additional fields in the deserialized instance
             CreateWorkspace 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 CreateWorkspace given an JSON string
   *
   * @param jsonString JSON string
   * @return An instance of CreateWorkspace
   * @throws IOException if the JSON string is invalid with respect to CreateWorkspace
   */
  public static CreateWorkspace fromJson(String jsonString) throws IOException {
    return JSON.getGson().fromJson(jsonString, CreateWorkspace.class);
  }

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

