/*
 * Michelin North America Order-to-Cash APIs
 * These APIs will help you to do business transactions with Michelin.  <br><br><b>Authentication details:</b><br> <br><u>Option A:</u> OAuth2 Client Credentials (recommended) <br><u>Option B:</u> API Key + Basic Authentication (not recommended) <br><br>To request your access, please contact your representative. <br><br>Our services are based on the EDIWHEEL standards. <br>You can find more information on the <a href=\"https://www.ediwheel.com/\" target=\"_blank\">EDIWHEEL website</a>. 
 *
 * The version of the OpenAPI document: 1.0.1
 * 
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */


package com.michelin.adk.amn.o2c.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 com.michelin.adk.amn.o2c.model.EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticleArticleDescription;
import com.michelin.adk.amn.o2c.model.EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticleArticleIdentification;
import com.michelin.adk.amn.o2c.model.EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticleDespatchedQuantity;
import com.michelin.adk.amn.o2c.model.EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticleTracingInformationInner;
import java.io.IOException;
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 com.michelin.adk.amn.JSON;

/**
 * EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticle
 */
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.12.0")
public class EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticle {
  public static final String SERIALIZED_NAME_ARTICLE_IDENTIFICATION = "articleIdentification";
  @SerializedName(SERIALIZED_NAME_ARTICLE_IDENTIFICATION)
  @javax.annotation.Nonnull
  private EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticleArticleIdentification articleIdentification;

  public static final String SERIALIZED_NAME_ARTICLE_DESCRIPTION = "articleDescription";
  @SerializedName(SERIALIZED_NAME_ARTICLE_DESCRIPTION)
  @javax.annotation.Nonnull
  private EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticleArticleDescription articleDescription;

  public static final String SERIALIZED_NAME_DESPATCHED_QUANTITY = "despatchedQuantity";
  @SerializedName(SERIALIZED_NAME_DESPATCHED_QUANTITY)
  @javax.annotation.Nonnull
  private EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticleDespatchedQuantity despatchedQuantity;

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

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

  public EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticle() {
  }

  public EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticle articleIdentification(@javax.annotation.Nonnull EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticleArticleIdentification articleIdentification) {
    this.articleIdentification = articleIdentification;
    return this;
  }

  /**
   * Get articleIdentification
   * @return articleIdentification
   */
  @javax.annotation.Nonnull
  public EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticleArticleIdentification getArticleIdentification() {
    return articleIdentification;
  }

  public void setArticleIdentification(@javax.annotation.Nonnull EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticleArticleIdentification articleIdentification) {
    this.articleIdentification = articleIdentification;
  }


  public EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticle articleDescription(@javax.annotation.Nonnull EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticleArticleDescription articleDescription) {
    this.articleDescription = articleDescription;
    return this;
  }

  /**
   * Get articleDescription
   * @return articleDescription
   */
  @javax.annotation.Nonnull
  public EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticleArticleDescription getArticleDescription() {
    return articleDescription;
  }

  public void setArticleDescription(@javax.annotation.Nonnull EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticleArticleDescription articleDescription) {
    this.articleDescription = articleDescription;
  }


  public EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticle despatchedQuantity(@javax.annotation.Nonnull EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticleDespatchedQuantity despatchedQuantity) {
    this.despatchedQuantity = despatchedQuantity;
    return this;
  }

  /**
   * Get despatchedQuantity
   * @return despatchedQuantity
   */
  @javax.annotation.Nonnull
  public EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticleDespatchedQuantity getDespatchedQuantity() {
    return despatchedQuantity;
  }

  public void setDespatchedQuantity(@javax.annotation.Nonnull EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticleDespatchedQuantity despatchedQuantity) {
    this.despatchedQuantity = despatchedQuantity;
  }


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

  public EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticle addDeliveryOptionItem(String deliveryOptionItem) {
    if (this.deliveryOption == null) {
      this.deliveryOption = new ArrayList<>();
    }
    this.deliveryOption.add(deliveryOptionItem);
    return this;
  }

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

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


  public EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticle tracingInformation(@javax.annotation.Nullable List<EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticleTracingInformationInner> tracingInformation) {
    this.tracingInformation = tracingInformation;
    return this;
  }

  public EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticle addTracingInformationItem(EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticleTracingInformationInner tracingInformationItem) {
    if (this.tracingInformation == null) {
      this.tracingInformation = new ArrayList<>();
    }
    this.tracingInformation.add(tracingInformationItem);
    return this;
  }

  /**
   * Tracking number information - repeated at line level. Small package shipments could include multiple tracking numbers repeated at each line level.
   * @return tracingInformation
   */
  @javax.annotation.Nullable
  public List<EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticleTracingInformationInner> getTracingInformation() {
    return tracingInformation;
  }

  public void setTracingInformation(@javax.annotation.Nullable List<EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticleTracingInformationInner> tracingInformation) {
    this.tracingInformation = tracingInformation;
  }



  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticle edIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticle = (EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticle) o;
    return Objects.equals(this.articleIdentification, edIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticle.articleIdentification) &&
        Objects.equals(this.articleDescription, edIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticle.articleDescription) &&
        Objects.equals(this.despatchedQuantity, edIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticle.despatchedQuantity) &&
        Objects.equals(this.deliveryOption, edIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticle.deliveryOption) &&
        Objects.equals(this.tracingInformation, edIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticle.tracingInformation);
  }

  @Override
  public int hashCode() {
    return Objects.hash(articleIdentification, articleDescription, despatchedQuantity, deliveryOption, tracingInformation);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticle {\n");
    sb.append("    articleIdentification: ").append(toIndentedString(articleIdentification)).append("\n");
    sb.append("    articleDescription: ").append(toIndentedString(articleDescription)).append("\n");
    sb.append("    despatchedQuantity: ").append(toIndentedString(despatchedQuantity)).append("\n");
    sb.append("    deliveryOption: ").append(toIndentedString(deliveryOption)).append("\n");
    sb.append("    tracingInformation: ").append(toIndentedString(tracingInformation)).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) {
    if (o == null) {
      return "null";
    }
    return 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>();
    openapiFields.add("articleIdentification");
    openapiFields.add("articleDescription");
    openapiFields.add("despatchedQuantity");
    openapiFields.add("deliveryOption");
    openapiFields.add("tracingInformation");

    // a set of required properties/fields (JSON key names)
    openapiRequiredFields = new HashSet<String>();
    openapiRequiredFields.add("articleIdentification");
    openapiRequiredFields.add("articleDescription");
    openapiRequiredFields.add("despatchedQuantity");
  }

  /**
   * 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 EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticle
   */
  public static void validateJsonElement(JsonElement jsonElement) throws IOException {
      if (jsonElement == null) {
        if (!EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticle.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null
          throw new IllegalArgumentException(String.format("The required field(s) %s in EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticle is not found in the empty JSON string", EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticle.openapiRequiredFields.toString()));
        }
      }

      Set<Map.Entry<String, JsonElement>> entries = jsonElement.getAsJsonObject().entrySet();
      // check to see if the JSON string contains additional fields
      for (Map.Entry<String, JsonElement> entry : entries) {
        if (!EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticle.openapiFields.contains(entry.getKey())) {
          throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticle` properties. JSON: %s", entry.getKey(), jsonElement.toString()));
        }
      }

      // check to make sure all required properties/fields are present in the JSON string
      for (String requiredField : EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticle.openapiRequiredFields) {
        if (jsonElement.getAsJsonObject().get(requiredField) == null) {
          throw new IllegalArgumentException(String.format("The required field `%s` is not found in the JSON string: %s", requiredField, jsonElement.toString()));
        }
      }
        JsonObject jsonObj = jsonElement.getAsJsonObject();
      // validate the required field `articleIdentification`
      EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticleArticleIdentification.validateJsonElement(jsonObj.get("articleIdentification"));
      // validate the required field `articleDescription`
      EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticleArticleDescription.validateJsonElement(jsonObj.get("articleDescription"));
      // validate the required field `despatchedQuantity`
      EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticleDespatchedQuantity.validateJsonElement(jsonObj.get("despatchedQuantity"));
      // ensure the optional json data is an array if present
      if (jsonObj.get("deliveryOption") != null && !jsonObj.get("deliveryOption").isJsonNull() && !jsonObj.get("deliveryOption").isJsonArray()) {
        throw new IllegalArgumentException(String.format("Expected the field `deliveryOption` to be an array in the JSON string but got `%s`", jsonObj.get("deliveryOption").toString()));
      }
      if (jsonObj.get("tracingInformation") != null && !jsonObj.get("tracingInformation").isJsonNull()) {
        JsonArray jsonArraytracingInformation = jsonObj.getAsJsonArray("tracingInformation");
        if (jsonArraytracingInformation != null) {
          // ensure the json data is an array
          if (!jsonObj.get("tracingInformation").isJsonArray()) {
            throw new IllegalArgumentException(String.format("Expected the field `tracingInformation` to be an array in the JSON string but got `%s`", jsonObj.get("tracingInformation").toString()));
          }

          // validate the optional field `tracingInformation` (array)
          for (int i = 0; i < jsonArraytracingInformation.size(); i++) {
            EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticleTracingInformationInner.validateJsonElement(jsonArraytracingInformation.get(i));
          };
        }
      }
  }

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

       return (TypeAdapter<T>) new TypeAdapter<EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticle>() {
           @Override
           public void write(JsonWriter out, EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticle value) throws IOException {
             JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
             elementAdapter.write(out, obj);
           }

           @Override
           public EDIWheelC10DesadvResponseDesadvInnerLineLevelInnerOrderedArticle read(JsonReader in) throws IOException {
             JsonElement jsonElement = elementAdapter.read(in);
             validateJsonElement(jsonElement);
             return thisAdapter.fromJsonTree(jsonElement);
           }

       }.nullSafe();
    }
  }

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

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

