/*
 * 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.EDIWheelB34InvoiceListRequestInvoiceInnerBuyerParty;
import com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListRequestInvoiceInnerConsignee;
import com.michelin.adk.amn.o2c.model.EDIWheelB34InvoiceListRequestInvoiceInnerReferences;
import java.io.IOException;
import java.util.Arrays;

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;

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

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

  /**
   * Document Type Codes available for use are as follows: 380 &#x3D; commercial invoice, 381 &#x3D; credit note, 383 &#x3D; debit note. If used in request, responses will be limited to items with the designated documentTypeCode.
   */
  @JsonAdapter(DocumentTypeCodeEnum.Adapter.class)
  public enum DocumentTypeCodeEnum {
    _380("380"),
    
    _381("381"),
    
    _383("383");

    private String value;

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

    public String getValue() {
      return value;
    }

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

    public static DocumentTypeCodeEnum fromValue(String value) {
      for (DocumentTypeCodeEnum b : DocumentTypeCodeEnum.values()) {
        if (b.value.equals(value)) {
          return b;
        }
      }
      throw new IllegalArgumentException("Unexpected value '" + value + "'");
    }

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

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

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

  public static final String SERIALIZED_NAME_DOCUMENT_TYPE_CODE = "documentTypeCode";
  @SerializedName(SERIALIZED_NAME_DOCUMENT_TYPE_CODE)
  @javax.annotation.Nullable
  private DocumentTypeCodeEnum documentTypeCode;

  public static final String SERIALIZED_NAME_BUYER_PARTY = "buyerParty";
  @SerializedName(SERIALIZED_NAME_BUYER_PARTY)
  @javax.annotation.Nonnull
  private EDIWheelB34InvoiceListRequestInvoiceInnerBuyerParty buyerParty;

  public static final String SERIALIZED_NAME_CONSIGNEE = "consignee";
  @SerializedName(SERIALIZED_NAME_CONSIGNEE)
  @javax.annotation.Nullable
  private EDIWheelB34InvoiceListRequestInvoiceInnerConsignee consignee;

  public static final String SERIALIZED_NAME_REFERENCES = "references";
  @SerializedName(SERIALIZED_NAME_REFERENCES)
  @javax.annotation.Nullable
  private EDIWheelB34InvoiceListRequestInvoiceInnerReferences references;

  /**
   * Attachment dictates response details to include as follows: \&quot;1\&quot; &#x3D; data only, \&quot;2\&quot; &#x3D; data + PDF base64 details, \&quot;3\&quot; &#x3D; PDF base64 details only
   */
  @JsonAdapter(AttachmentEnum.Adapter.class)
  public enum AttachmentEnum {
    _1("1"),
    
    _2("2"),
    
    _3("3");

    private String value;

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

    public String getValue() {
      return value;
    }

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

    public static AttachmentEnum fromValue(String value) {
      for (AttachmentEnum b : AttachmentEnum.values()) {
        if (b.value.equals(value)) {
          return b;
        }
      }
      throw new IllegalArgumentException("Unexpected value '" + value + "'");
    }

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

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

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

  public static final String SERIALIZED_NAME_ATTACHMENT = "attachment";
  @SerializedName(SERIALIZED_NAME_ATTACHMENT)
  @javax.annotation.Nonnull
  private AttachmentEnum attachment;

  public EDIWheelB34InvoiceListRequestInvoiceInner() {
  }

  public EDIWheelB34InvoiceListRequestInvoiceInner invoiceIssueFromDate(@javax.annotation.Nullable String invoiceIssueFromDate) {
    this.invoiceIssueFromDate = invoiceIssueFromDate;
    return this;
  }

  /**
   * From Date value for Date Range searches. Format YYYY-MM-DD. Date range cannot be used in conjunction with other reference(s) as selection criteria. Date range OR references would need to be included in request. Max date range &#x3D; 30 days. Depending on volume of activity, smaller range searches are recommended.
   * @return invoiceIssueFromDate
   */
  @javax.annotation.Nullable
  public String getInvoiceIssueFromDate() {
    return invoiceIssueFromDate;
  }

  public void setInvoiceIssueFromDate(@javax.annotation.Nullable String invoiceIssueFromDate) {
    this.invoiceIssueFromDate = invoiceIssueFromDate;
  }


  public EDIWheelB34InvoiceListRequestInvoiceInner invoiceIssueToDate(@javax.annotation.Nullable String invoiceIssueToDate) {
    this.invoiceIssueToDate = invoiceIssueToDate;
    return this;
  }

  /**
   * To Date value for Date Range searches. Format YYYY-MM-DD. Date range cannot be used in conjunction with other reference(s) as selection criteria. Date range OR references would need to be included in request. Max date range &#x3D; 30 days. Depending on volume of activity, smaller range searches are recommended.
   * @return invoiceIssueToDate
   */
  @javax.annotation.Nullable
  public String getInvoiceIssueToDate() {
    return invoiceIssueToDate;
  }

  public void setInvoiceIssueToDate(@javax.annotation.Nullable String invoiceIssueToDate) {
    this.invoiceIssueToDate = invoiceIssueToDate;
  }


  public EDIWheelB34InvoiceListRequestInvoiceInner documentTypeCode(@javax.annotation.Nullable DocumentTypeCodeEnum documentTypeCode) {
    this.documentTypeCode = documentTypeCode;
    return this;
  }

  /**
   * Document Type Codes available for use are as follows: 380 &#x3D; commercial invoice, 381 &#x3D; credit note, 383 &#x3D; debit note. If used in request, responses will be limited to items with the designated documentTypeCode.
   * @return documentTypeCode
   */
  @javax.annotation.Nullable
  public DocumentTypeCodeEnum getDocumentTypeCode() {
    return documentTypeCode;
  }

  public void setDocumentTypeCode(@javax.annotation.Nullable DocumentTypeCodeEnum documentTypeCode) {
    this.documentTypeCode = documentTypeCode;
  }


  public EDIWheelB34InvoiceListRequestInvoiceInner buyerParty(@javax.annotation.Nonnull EDIWheelB34InvoiceListRequestInvoiceInnerBuyerParty buyerParty) {
    this.buyerParty = buyerParty;
    return this;
  }

  /**
   * Get buyerParty
   * @return buyerParty
   */
  @javax.annotation.Nonnull
  public EDIWheelB34InvoiceListRequestInvoiceInnerBuyerParty getBuyerParty() {
    return buyerParty;
  }

  public void setBuyerParty(@javax.annotation.Nonnull EDIWheelB34InvoiceListRequestInvoiceInnerBuyerParty buyerParty) {
    this.buyerParty = buyerParty;
  }


  public EDIWheelB34InvoiceListRequestInvoiceInner consignee(@javax.annotation.Nullable EDIWheelB34InvoiceListRequestInvoiceInnerConsignee consignee) {
    this.consignee = consignee;
    return this;
  }

  /**
   * Get consignee
   * @return consignee
   */
  @javax.annotation.Nullable
  public EDIWheelB34InvoiceListRequestInvoiceInnerConsignee getConsignee() {
    return consignee;
  }

  public void setConsignee(@javax.annotation.Nullable EDIWheelB34InvoiceListRequestInvoiceInnerConsignee consignee) {
    this.consignee = consignee;
  }


  public EDIWheelB34InvoiceListRequestInvoiceInner references(@javax.annotation.Nullable EDIWheelB34InvoiceListRequestInvoiceInnerReferences references) {
    this.references = references;
    return this;
  }

  /**
   * Get references
   * @return references
   */
  @javax.annotation.Nullable
  public EDIWheelB34InvoiceListRequestInvoiceInnerReferences getReferences() {
    return references;
  }

  public void setReferences(@javax.annotation.Nullable EDIWheelB34InvoiceListRequestInvoiceInnerReferences references) {
    this.references = references;
  }


  public EDIWheelB34InvoiceListRequestInvoiceInner attachment(@javax.annotation.Nonnull AttachmentEnum attachment) {
    this.attachment = attachment;
    return this;
  }

  /**
   * Attachment dictates response details to include as follows: \&quot;1\&quot; &#x3D; data only, \&quot;2\&quot; &#x3D; data + PDF base64 details, \&quot;3\&quot; &#x3D; PDF base64 details only
   * @return attachment
   */
  @javax.annotation.Nonnull
  public AttachmentEnum getAttachment() {
    return attachment;
  }

  public void setAttachment(@javax.annotation.Nonnull AttachmentEnum attachment) {
    this.attachment = attachment;
  }



  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    EDIWheelB34InvoiceListRequestInvoiceInner edIWheelB34InvoiceListRequestInvoiceInner = (EDIWheelB34InvoiceListRequestInvoiceInner) o;
    return Objects.equals(this.invoiceIssueFromDate, edIWheelB34InvoiceListRequestInvoiceInner.invoiceIssueFromDate) &&
        Objects.equals(this.invoiceIssueToDate, edIWheelB34InvoiceListRequestInvoiceInner.invoiceIssueToDate) &&
        Objects.equals(this.documentTypeCode, edIWheelB34InvoiceListRequestInvoiceInner.documentTypeCode) &&
        Objects.equals(this.buyerParty, edIWheelB34InvoiceListRequestInvoiceInner.buyerParty) &&
        Objects.equals(this.consignee, edIWheelB34InvoiceListRequestInvoiceInner.consignee) &&
        Objects.equals(this.references, edIWheelB34InvoiceListRequestInvoiceInner.references) &&
        Objects.equals(this.attachment, edIWheelB34InvoiceListRequestInvoiceInner.attachment);
  }

  @Override
  public int hashCode() {
    return Objects.hash(invoiceIssueFromDate, invoiceIssueToDate, documentTypeCode, buyerParty, consignee, references, attachment);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class EDIWheelB34InvoiceListRequestInvoiceInner {\n");
    sb.append("    invoiceIssueFromDate: ").append(toIndentedString(invoiceIssueFromDate)).append("\n");
    sb.append("    invoiceIssueToDate: ").append(toIndentedString(invoiceIssueToDate)).append("\n");
    sb.append("    documentTypeCode: ").append(toIndentedString(documentTypeCode)).append("\n");
    sb.append("    buyerParty: ").append(toIndentedString(buyerParty)).append("\n");
    sb.append("    consignee: ").append(toIndentedString(consignee)).append("\n");
    sb.append("    references: ").append(toIndentedString(references)).append("\n");
    sb.append("    attachment: ").append(toIndentedString(attachment)).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("invoiceIssueFromDate");
    openapiFields.add("invoiceIssueToDate");
    openapiFields.add("documentTypeCode");
    openapiFields.add("buyerParty");
    openapiFields.add("consignee");
    openapiFields.add("references");
    openapiFields.add("attachment");

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

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

      // check to make sure all required properties/fields are present in the JSON string
      for (String requiredField : EDIWheelB34InvoiceListRequestInvoiceInner.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("invoiceIssueFromDate") != null && !jsonObj.get("invoiceIssueFromDate").isJsonNull()) && !jsonObj.get("invoiceIssueFromDate").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `invoiceIssueFromDate` to be a primitive type in the JSON string but got `%s`", jsonObj.get("invoiceIssueFromDate").toString()));
      }
      if ((jsonObj.get("invoiceIssueToDate") != null && !jsonObj.get("invoiceIssueToDate").isJsonNull()) && !jsonObj.get("invoiceIssueToDate").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `invoiceIssueToDate` to be a primitive type in the JSON string but got `%s`", jsonObj.get("invoiceIssueToDate").toString()));
      }
      if ((jsonObj.get("documentTypeCode") != null && !jsonObj.get("documentTypeCode").isJsonNull()) && !jsonObj.get("documentTypeCode").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `documentTypeCode` to be a primitive type in the JSON string but got `%s`", jsonObj.get("documentTypeCode").toString()));
      }
      // validate the optional field `documentTypeCode`
      if (jsonObj.get("documentTypeCode") != null && !jsonObj.get("documentTypeCode").isJsonNull()) {
        DocumentTypeCodeEnum.validateJsonElement(jsonObj.get("documentTypeCode"));
      }
      // validate the required field `buyerParty`
      EDIWheelB34InvoiceListRequestInvoiceInnerBuyerParty.validateJsonElement(jsonObj.get("buyerParty"));
      // validate the optional field `consignee`
      if (jsonObj.get("consignee") != null && !jsonObj.get("consignee").isJsonNull()) {
        EDIWheelB34InvoiceListRequestInvoiceInnerConsignee.validateJsonElement(jsonObj.get("consignee"));
      }
      // validate the optional field `references`
      if (jsonObj.get("references") != null && !jsonObj.get("references").isJsonNull()) {
        EDIWheelB34InvoiceListRequestInvoiceInnerReferences.validateJsonElement(jsonObj.get("references"));
      }
      if (!jsonObj.get("attachment").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `attachment` to be a primitive type in the JSON string but got `%s`", jsonObj.get("attachment").toString()));
      }
      // validate the required field `attachment`
      AttachmentEnum.validateJsonElement(jsonObj.get("attachment"));
  }

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

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

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

       }.nullSafe();
    }
  }

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

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

