/*
 * Daytona Toolbox API
 * Daytona Toolbox API
 *
 * The version of the OpenAPI document: v0.0.0-dev
 * 
 *
 * 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.toolbox.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.toolbox.client.model.ChartElement;
import java.io.IOException;
import java.math.BigDecimal;
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.toolbox.client.JSON;

/**
 * Chart
 */
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.21.0")
public class Chart {
  public static final String SERIALIZED_NAME_ELEMENTS = "elements";
  @SerializedName(SERIALIZED_NAME_ELEMENTS)
  @javax.annotation.Nullable
  private List<ChartElement> elements = new ArrayList<>();

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

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

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

  public static final String SERIALIZED_NAME_X_LABEL = "x_label";
  @SerializedName(SERIALIZED_NAME_X_LABEL)
  @javax.annotation.Nullable
  private String xLabel;

  public static final String SERIALIZED_NAME_X_SCALE = "x_scale";
  @SerializedName(SERIALIZED_NAME_X_SCALE)
  @javax.annotation.Nullable
  private String xScale;

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

  public static final String SERIALIZED_NAME_X_TICKS = "x_ticks";
  @SerializedName(SERIALIZED_NAME_X_TICKS)
  @javax.annotation.Nullable
  private List<BigDecimal> xTicks = new ArrayList<>();

  public static final String SERIALIZED_NAME_Y_LABEL = "y_label";
  @SerializedName(SERIALIZED_NAME_Y_LABEL)
  @javax.annotation.Nullable
  private String yLabel;

  public static final String SERIALIZED_NAME_Y_SCALE = "y_scale";
  @SerializedName(SERIALIZED_NAME_Y_SCALE)
  @javax.annotation.Nullable
  private String yScale;

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

  public static final String SERIALIZED_NAME_Y_TICKS = "y_ticks";
  @SerializedName(SERIALIZED_NAME_Y_TICKS)
  @javax.annotation.Nullable
  private List<BigDecimal> yTicks = new ArrayList<>();

  public Chart() {
  }

  public Chart elements(@javax.annotation.Nullable List<ChartElement> elements) {
    this.elements = elements;
    return this;
  }

  public Chart addElementsItem(ChartElement elementsItem) {
    if (this.elements == null) {
      this.elements = new ArrayList<>();
    }
    this.elements.add(elementsItem);
    return this;
  }

  /**
   * Get elements
   * @return elements
   */
  @javax.annotation.Nullable
  public List<ChartElement> getElements() {
    return elements;
  }

  public void setElements(@javax.annotation.Nullable List<ChartElement> elements) {
    this.elements = elements;
  }


  public Chart png(@javax.annotation.Nullable String png) {
    this.png = png;
    return this;
  }

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

  public void setPng(@javax.annotation.Nullable String png) {
    this.png = png;
  }


  public Chart title(@javax.annotation.Nullable String title) {
    this.title = title;
    return this;
  }

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

  public void setTitle(@javax.annotation.Nullable String title) {
    this.title = title;
  }


  public Chart type(@javax.annotation.Nullable String type) {
    this.type = type;
    return this;
  }

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

  public void setType(@javax.annotation.Nullable String type) {
    this.type = type;
  }


  public Chart xLabel(@javax.annotation.Nullable String xLabel) {
    this.xLabel = xLabel;
    return this;
  }

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

  public void setxLabel(@javax.annotation.Nullable String xLabel) {
    this.xLabel = xLabel;
  }


  public Chart xScale(@javax.annotation.Nullable String xScale) {
    this.xScale = xScale;
    return this;
  }

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

  public void setxScale(@javax.annotation.Nullable String xScale) {
    this.xScale = xScale;
  }


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

  public Chart addXTickLabelsItem(String xTickLabelsItem) {
    if (this.xTickLabels == null) {
      this.xTickLabels = new ArrayList<>();
    }
    this.xTickLabels.add(xTickLabelsItem);
    return this;
  }

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

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


  public Chart xTicks(@javax.annotation.Nullable List<BigDecimal> xTicks) {
    this.xTicks = xTicks;
    return this;
  }

  public Chart addXTicksItem(BigDecimal xTicksItem) {
    if (this.xTicks == null) {
      this.xTicks = new ArrayList<>();
    }
    this.xTicks.add(xTicksItem);
    return this;
  }

  /**
   * Get xTicks
   * @return xTicks
   */
  @javax.annotation.Nullable
  public List<BigDecimal> getxTicks() {
    return xTicks;
  }

  public void setxTicks(@javax.annotation.Nullable List<BigDecimal> xTicks) {
    this.xTicks = xTicks;
  }


  public Chart yLabel(@javax.annotation.Nullable String yLabel) {
    this.yLabel = yLabel;
    return this;
  }

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

  public void setyLabel(@javax.annotation.Nullable String yLabel) {
    this.yLabel = yLabel;
  }


  public Chart yScale(@javax.annotation.Nullable String yScale) {
    this.yScale = yScale;
    return this;
  }

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

  public void setyScale(@javax.annotation.Nullable String yScale) {
    this.yScale = yScale;
  }


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

  public Chart addYTickLabelsItem(String yTickLabelsItem) {
    if (this.yTickLabels == null) {
      this.yTickLabels = new ArrayList<>();
    }
    this.yTickLabels.add(yTickLabelsItem);
    return this;
  }

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

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


  public Chart yTicks(@javax.annotation.Nullable List<BigDecimal> yTicks) {
    this.yTicks = yTicks;
    return this;
  }

  public Chart addYTicksItem(BigDecimal yTicksItem) {
    if (this.yTicks == null) {
      this.yTicks = new ArrayList<>();
    }
    this.yTicks.add(yTicksItem);
    return this;
  }

  /**
   * Get yTicks
   * @return yTicks
   */
  @javax.annotation.Nullable
  public List<BigDecimal> getyTicks() {
    return yTicks;
  }

  public void setyTicks(@javax.annotation.Nullable List<BigDecimal> yTicks) {
    this.yTicks = yTicks;
  }

  /**
   * 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 Chart instance itself
   */
  public Chart 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;
    }
    Chart chart = (Chart) o;
    return Objects.equals(this.elements, chart.elements) &&
        Objects.equals(this.png, chart.png) &&
        Objects.equals(this.title, chart.title) &&
        Objects.equals(this.type, chart.type) &&
        Objects.equals(this.xLabel, chart.xLabel) &&
        Objects.equals(this.xScale, chart.xScale) &&
        Objects.equals(this.xTickLabels, chart.xTickLabels) &&
        Objects.equals(this.xTicks, chart.xTicks) &&
        Objects.equals(this.yLabel, chart.yLabel) &&
        Objects.equals(this.yScale, chart.yScale) &&
        Objects.equals(this.yTickLabels, chart.yTickLabels) &&
        Objects.equals(this.yTicks, chart.yTicks)&&
        Objects.equals(this.additionalProperties, chart.additionalProperties);
  }

  @Override
  public int hashCode() {
    return Objects.hash(elements, png, title, type, xLabel, xScale, xTickLabels, xTicks, yLabel, yScale, yTickLabels, yTicks, additionalProperties);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class Chart {\n");
    sb.append("    elements: ").append(toIndentedString(elements)).append("\n");
    sb.append("    png: ").append(toIndentedString(png)).append("\n");
    sb.append("    title: ").append(toIndentedString(title)).append("\n");
    sb.append("    type: ").append(toIndentedString(type)).append("\n");
    sb.append("    xLabel: ").append(toIndentedString(xLabel)).append("\n");
    sb.append("    xScale: ").append(toIndentedString(xScale)).append("\n");
    sb.append("    xTickLabels: ").append(toIndentedString(xTickLabels)).append("\n");
    sb.append("    xTicks: ").append(toIndentedString(xTicks)).append("\n");
    sb.append("    yLabel: ").append(toIndentedString(yLabel)).append("\n");
    sb.append("    yScale: ").append(toIndentedString(yScale)).append("\n");
    sb.append("    yTickLabels: ").append(toIndentedString(yTickLabels)).append("\n");
    sb.append("    yTicks: ").append(toIndentedString(yTicks)).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("elements", "png", "title", "type", "x_label", "x_scale", "x_tick_labels", "x_ticks", "y_label", "y_scale", "y_tick_labels", "y_ticks"));

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

          // validate the optional field `elements` (array)
          for (int i = 0; i < jsonArrayelements.size(); i++) {
            ChartElement.validateJsonElement(jsonArrayelements.get(i));
          };
        }
      }
      if ((jsonObj.get("png") != null && !jsonObj.get("png").isJsonNull()) && !jsonObj.get("png").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `png` to be a primitive type in the JSON string but got `%s`", jsonObj.get("png").toString()));
      }
      if ((jsonObj.get("title") != null && !jsonObj.get("title").isJsonNull()) && !jsonObj.get("title").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `title` to be a primitive type in the JSON string but got `%s`", jsonObj.get("title").toString()));
      }
      if ((jsonObj.get("type") != null && !jsonObj.get("type").isJsonNull()) && !jsonObj.get("type").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `type` to be a primitive type in the JSON string but got `%s`", jsonObj.get("type").toString()));
      }
      if ((jsonObj.get("x_label") != null && !jsonObj.get("x_label").isJsonNull()) && !jsonObj.get("x_label").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `x_label` to be a primitive type in the JSON string but got `%s`", jsonObj.get("x_label").toString()));
      }
      if ((jsonObj.get("x_scale") != null && !jsonObj.get("x_scale").isJsonNull()) && !jsonObj.get("x_scale").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `x_scale` to be a primitive type in the JSON string but got `%s`", jsonObj.get("x_scale").toString()));
      }
      // ensure the optional json data is an array if present
      if (jsonObj.get("x_tick_labels") != null && !jsonObj.get("x_tick_labels").isJsonNull() && !jsonObj.get("x_tick_labels").isJsonArray()) {
        throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `x_tick_labels` to be an array in the JSON string but got `%s`", jsonObj.get("x_tick_labels").toString()));
      }
      // ensure the optional json data is an array if present
      if (jsonObj.get("x_ticks") != null && !jsonObj.get("x_ticks").isJsonNull() && !jsonObj.get("x_ticks").isJsonArray()) {
        throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `x_ticks` to be an array in the JSON string but got `%s`", jsonObj.get("x_ticks").toString()));
      }
      if ((jsonObj.get("y_label") != null && !jsonObj.get("y_label").isJsonNull()) && !jsonObj.get("y_label").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `y_label` to be a primitive type in the JSON string but got `%s`", jsonObj.get("y_label").toString()));
      }
      if ((jsonObj.get("y_scale") != null && !jsonObj.get("y_scale").isJsonNull()) && !jsonObj.get("y_scale").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `y_scale` to be a primitive type in the JSON string but got `%s`", jsonObj.get("y_scale").toString()));
      }
      // ensure the optional json data is an array if present
      if (jsonObj.get("y_tick_labels") != null && !jsonObj.get("y_tick_labels").isJsonNull() && !jsonObj.get("y_tick_labels").isJsonArray()) {
        throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `y_tick_labels` to be an array in the JSON string but got `%s`", jsonObj.get("y_tick_labels").toString()));
      }
      // ensure the optional json data is an array if present
      if (jsonObj.get("y_ticks") != null && !jsonObj.get("y_ticks").isJsonNull() && !jsonObj.get("y_ticks").isJsonArray()) {
        throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `y_ticks` to be an array in the JSON string but got `%s`", jsonObj.get("y_ticks").toString()));
      }
  }

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

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

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

