/*
 * 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.EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderLineInner;
import com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderReference;
import com.michelin.adk.amn.o2c.model.EDIWheelC11OrderStatusResponseReferencedOrderInnerSupplierOrderNumber;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.openapitools.jackson.nullable.JsonNullable;

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;

/**
 * EDIWheelC11OrderStatusResponseReferencedOrderInner
 */
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.12.0")
public class EDIWheelC11OrderStatusResponseReferencedOrderInner {
  public static final String SERIALIZED_NAME_ERROR = "error";
  @SerializedName(SERIALIZED_NAME_ERROR)
  @javax.annotation.Nullable
  private Object error;

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

  public static final String SERIALIZED_NAME_SUPPLIER_ORDER_NUMBER = "supplierOrderNumber";
  @SerializedName(SERIALIZED_NAME_SUPPLIER_ORDER_NUMBER)
  @javax.annotation.Nonnull
  private EDIWheelC11OrderStatusResponseReferencedOrderInnerSupplierOrderNumber supplierOrderNumber;

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

  public static final String SERIALIZED_NAME_ORDER_REFERENCE = "orderReference";
  @SerializedName(SERIALIZED_NAME_ORDER_REFERENCE)
  @javax.annotation.Nonnull
  private EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderReference orderReference;

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

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

  public static final String SERIALIZED_NAME_SELLER_PARTY = "sellerParty";
  @SerializedName(SERIALIZED_NAME_SELLER_PARTY)
  @javax.annotation.Nullable
  private Object sellerParty;

  public static final String SERIALIZED_NAME_SUPPLIER_PARTY = "supplierParty";
  @SerializedName(SERIALIZED_NAME_SUPPLIER_PARTY)
  @javax.annotation.Nullable
  private Object supplierParty;

  public static final String SERIALIZED_NAME_CONTRACT = "contract";
  @SerializedName(SERIALIZED_NAME_CONTRACT)
  @javax.annotation.Nullable
  private Object contract;

  public static final String SERIALIZED_NAME_ORDER_LINE = "orderLine";
  @SerializedName(SERIALIZED_NAME_ORDER_LINE)
  @javax.annotation.Nonnull
  private List<EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderLineInner> orderLine = new ArrayList<>();

  public EDIWheelC11OrderStatusResponseReferencedOrderInner() {
  }

  public EDIWheelC11OrderStatusResponseReferencedOrderInner error(@javax.annotation.Nullable Object error) {
    this.error = error;
    return this;
  }

  /**
   * Get error
   * @return error
   */
  @javax.annotation.Nullable
  public Object getError() {
    return error;
  }

  public void setError(@javax.annotation.Nullable Object error) {
    this.error = error;
  }


  public EDIWheelC11OrderStatusResponseReferencedOrderInner orderDate(@javax.annotation.Nonnull String orderDate) {
    this.orderDate = orderDate;
    return this;
  }

  /**
   * Date order received in Michelin systems. Format YYYY-MM-DD
   * @return orderDate
   */
  @javax.annotation.Nonnull
  public String getOrderDate() {
    return orderDate;
  }

  public void setOrderDate(@javax.annotation.Nonnull String orderDate) {
    this.orderDate = orderDate;
  }


  public EDIWheelC11OrderStatusResponseReferencedOrderInner supplierOrderNumber(@javax.annotation.Nonnull EDIWheelC11OrderStatusResponseReferencedOrderInnerSupplierOrderNumber supplierOrderNumber) {
    this.supplierOrderNumber = supplierOrderNumber;
    return this;
  }

  /**
   * Get supplierOrderNumber
   * @return supplierOrderNumber
   */
  @javax.annotation.Nonnull
  public EDIWheelC11OrderStatusResponseReferencedOrderInnerSupplierOrderNumber getSupplierOrderNumber() {
    return supplierOrderNumber;
  }

  public void setSupplierOrderNumber(@javax.annotation.Nonnull EDIWheelC11OrderStatusResponseReferencedOrderInnerSupplierOrderNumber supplierOrderNumber) {
    this.supplierOrderNumber = supplierOrderNumber;
  }


  public EDIWheelC11OrderStatusResponseReferencedOrderInner orderingMethod(@javax.annotation.Nonnull String orderingMethod) {
    this.orderingMethod = orderingMethod;
    return this;
  }

  /**
   * Method by which order was received. Possible responses could include: CSR KEYED, INTERNET, EDI PO, TELEPHONY, VMI, ERPEBIB, S2S INTEGRATION
   * @return orderingMethod
   */
  @javax.annotation.Nonnull
  public String getOrderingMethod() {
    return orderingMethod;
  }

  public void setOrderingMethod(@javax.annotation.Nonnull String orderingMethod) {
    this.orderingMethod = orderingMethod;
  }


  public EDIWheelC11OrderStatusResponseReferencedOrderInner orderReference(@javax.annotation.Nonnull EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderReference orderReference) {
    this.orderReference = orderReference;
    return this;
  }

  /**
   * Get orderReference
   * @return orderReference
   */
  @javax.annotation.Nonnull
  public EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderReference getOrderReference() {
    return orderReference;
  }

  public void setOrderReference(@javax.annotation.Nonnull EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderReference orderReference) {
    this.orderReference = orderReference;
  }


  public EDIWheelC11OrderStatusResponseReferencedOrderInner pickUp(@javax.annotation.Nullable String pickUp) {
    this.pickUp = pickUp;
    return this;
  }

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

  public void setPickUp(@javax.annotation.Nullable String pickUp) {
    this.pickUp = pickUp;
  }


  public EDIWheelC11OrderStatusResponseReferencedOrderInner deliveryOption(@javax.annotation.Nullable String deliveryOption) {
    this.deliveryOption = deliveryOption;
    return this;
  }

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

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


  public EDIWheelC11OrderStatusResponseReferencedOrderInner sellerParty(@javax.annotation.Nullable Object sellerParty) {
    this.sellerParty = sellerParty;
    return this;
  }

  /**
   * Get sellerParty
   * @return sellerParty
   */
  @javax.annotation.Nullable
  public Object getSellerParty() {
    return sellerParty;
  }

  public void setSellerParty(@javax.annotation.Nullable Object sellerParty) {
    this.sellerParty = sellerParty;
  }


  public EDIWheelC11OrderStatusResponseReferencedOrderInner supplierParty(@javax.annotation.Nullable Object supplierParty) {
    this.supplierParty = supplierParty;
    return this;
  }

  /**
   * Get supplierParty
   * @return supplierParty
   */
  @javax.annotation.Nullable
  public Object getSupplierParty() {
    return supplierParty;
  }

  public void setSupplierParty(@javax.annotation.Nullable Object supplierParty) {
    this.supplierParty = supplierParty;
  }


  public EDIWheelC11OrderStatusResponseReferencedOrderInner contract(@javax.annotation.Nullable Object contract) {
    this.contract = contract;
    return this;
  }

  /**
   * Get contract
   * @return contract
   */
  @javax.annotation.Nullable
  public Object getContract() {
    return contract;
  }

  public void setContract(@javax.annotation.Nullable Object contract) {
    this.contract = contract;
  }


  public EDIWheelC11OrderStatusResponseReferencedOrderInner orderLine(@javax.annotation.Nonnull List<EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderLineInner> orderLine) {
    this.orderLine = orderLine;
    return this;
  }

  public EDIWheelC11OrderStatusResponseReferencedOrderInner addOrderLineItem(EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderLineInner orderLineItem) {
    if (this.orderLine == null) {
      this.orderLine = new ArrayList<>();
    }
    this.orderLine.add(orderLineItem);
    return this;
  }

  /**
   * Get orderLine
   * @return orderLine
   */
  @javax.annotation.Nonnull
  public List<EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderLineInner> getOrderLine() {
    return orderLine;
  }

  public void setOrderLine(@javax.annotation.Nonnull List<EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderLineInner> orderLine) {
    this.orderLine = orderLine;
  }



  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    EDIWheelC11OrderStatusResponseReferencedOrderInner edIWheelC11OrderStatusResponseReferencedOrderInner = (EDIWheelC11OrderStatusResponseReferencedOrderInner) o;
    return Objects.equals(this.error, edIWheelC11OrderStatusResponseReferencedOrderInner.error) &&
        Objects.equals(this.orderDate, edIWheelC11OrderStatusResponseReferencedOrderInner.orderDate) &&
        Objects.equals(this.supplierOrderNumber, edIWheelC11OrderStatusResponseReferencedOrderInner.supplierOrderNumber) &&
        Objects.equals(this.orderingMethod, edIWheelC11OrderStatusResponseReferencedOrderInner.orderingMethod) &&
        Objects.equals(this.orderReference, edIWheelC11OrderStatusResponseReferencedOrderInner.orderReference) &&
        Objects.equals(this.pickUp, edIWheelC11OrderStatusResponseReferencedOrderInner.pickUp) &&
        Objects.equals(this.deliveryOption, edIWheelC11OrderStatusResponseReferencedOrderInner.deliveryOption) &&
        Objects.equals(this.sellerParty, edIWheelC11OrderStatusResponseReferencedOrderInner.sellerParty) &&
        Objects.equals(this.supplierParty, edIWheelC11OrderStatusResponseReferencedOrderInner.supplierParty) &&
        Objects.equals(this.contract, edIWheelC11OrderStatusResponseReferencedOrderInner.contract) &&
        Objects.equals(this.orderLine, edIWheelC11OrderStatusResponseReferencedOrderInner.orderLine);
  }

  private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
    return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && Objects.deepEquals(a.get(), b.get()));
  }

  @Override
  public int hashCode() {
    return Objects.hash(error, orderDate, supplierOrderNumber, orderingMethod, orderReference, pickUp, deliveryOption, sellerParty, supplierParty, contract, orderLine);
  }

  private static <T> int hashCodeNullable(JsonNullable<T> a) {
    if (a == null) {
      return 1;
    }
    return a.isPresent() ? Arrays.deepHashCode(new Object[]{a.get()}) : 31;
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class EDIWheelC11OrderStatusResponseReferencedOrderInner {\n");
    sb.append("    error: ").append(toIndentedString(error)).append("\n");
    sb.append("    orderDate: ").append(toIndentedString(orderDate)).append("\n");
    sb.append("    supplierOrderNumber: ").append(toIndentedString(supplierOrderNumber)).append("\n");
    sb.append("    orderingMethod: ").append(toIndentedString(orderingMethod)).append("\n");
    sb.append("    orderReference: ").append(toIndentedString(orderReference)).append("\n");
    sb.append("    pickUp: ").append(toIndentedString(pickUp)).append("\n");
    sb.append("    deliveryOption: ").append(toIndentedString(deliveryOption)).append("\n");
    sb.append("    sellerParty: ").append(toIndentedString(sellerParty)).append("\n");
    sb.append("    supplierParty: ").append(toIndentedString(supplierParty)).append("\n");
    sb.append("    contract: ").append(toIndentedString(contract)).append("\n");
    sb.append("    orderLine: ").append(toIndentedString(orderLine)).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("error");
    openapiFields.add("orderDate");
    openapiFields.add("supplierOrderNumber");
    openapiFields.add("orderingMethod");
    openapiFields.add("orderReference");
    openapiFields.add("pickUp");
    openapiFields.add("deliveryOption");
    openapiFields.add("sellerParty");
    openapiFields.add("supplierParty");
    openapiFields.add("contract");
    openapiFields.add("orderLine");

    // a set of required properties/fields (JSON key names)
    openapiRequiredFields = new HashSet<String>();
    openapiRequiredFields.add("orderDate");
    openapiRequiredFields.add("supplierOrderNumber");
    openapiRequiredFields.add("orderingMethod");
    openapiRequiredFields.add("orderReference");
    openapiRequiredFields.add("orderLine");
  }

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

      // check to make sure all required properties/fields are present in the JSON string
      for (String requiredField : EDIWheelC11OrderStatusResponseReferencedOrderInner.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();
      if (!jsonObj.get("orderDate").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `orderDate` to be a primitive type in the JSON string but got `%s`", jsonObj.get("orderDate").toString()));
      }
      // validate the required field `supplierOrderNumber`
      EDIWheelC11OrderStatusResponseReferencedOrderInnerSupplierOrderNumber.validateJsonElement(jsonObj.get("supplierOrderNumber"));
      if (!jsonObj.get("orderingMethod").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `orderingMethod` to be a primitive type in the JSON string but got `%s`", jsonObj.get("orderingMethod").toString()));
      }
      // validate the required field `orderReference`
      EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderReference.validateJsonElement(jsonObj.get("orderReference"));
      if ((jsonObj.get("pickUp") != null && !jsonObj.get("pickUp").isJsonNull()) && !jsonObj.get("pickUp").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `pickUp` to be a primitive type in the JSON string but got `%s`", jsonObj.get("pickUp").toString()));
      }
      if ((jsonObj.get("deliveryOption") != null && !jsonObj.get("deliveryOption").isJsonNull()) && !jsonObj.get("deliveryOption").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `deliveryOption` to be a primitive type in the JSON string but got `%s`", jsonObj.get("deliveryOption").toString()));
      }
      // ensure the json data is an array
      if (!jsonObj.get("orderLine").isJsonArray()) {
        throw new IllegalArgumentException(String.format("Expected the field `orderLine` to be an array in the JSON string but got `%s`", jsonObj.get("orderLine").toString()));
      }

      JsonArray jsonArrayorderLine = jsonObj.getAsJsonArray("orderLine");
      // validate the required field `orderLine` (array)
      for (int i = 0; i < jsonArrayorderLine.size(); i++) {
        EDIWheelC11OrderStatusResponseReferencedOrderInnerOrderLineInner.validateJsonElement(jsonArrayorderLine.get(i));
      };
  }

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

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

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

       }.nullSafe();
    }
  }

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

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

