/*
 * Kubernetes
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * The version of the OpenAPI document: v1.21.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 io.cert.manager.models;

import java.util.Objects;
import java.util.Arrays;
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.cert.manager.models.V1ClusterIssuerSpecAcme;
import io.cert.manager.models.V1ClusterIssuerSpecCa;
import io.cert.manager.models.V1ClusterIssuerSpecSelfSigned;
import io.cert.manager.models.V1ClusterIssuerSpecVault;
import io.cert.manager.models.V1ClusterIssuerSpecVenafi;
import java.io.IOException;

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.lang.reflect.Type;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import io.kubernetes.client.openapi.JSON;

/**
 * Desired state of the Issuer resource.
 */
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2024-03-01T07:00:20.132973Z[Etc/UTC]")
public class V1IssuerSpec {
  public static final String SERIALIZED_NAME_ACME = "acme";
  @SerializedName(SERIALIZED_NAME_ACME)
  private V1ClusterIssuerSpecAcme acme;

  public static final String SERIALIZED_NAME_CA = "ca";
  @SerializedName(SERIALIZED_NAME_CA)
  private V1ClusterIssuerSpecCa ca;

  public static final String SERIALIZED_NAME_SELF_SIGNED = "selfSigned";
  @SerializedName(SERIALIZED_NAME_SELF_SIGNED)
  private V1ClusterIssuerSpecSelfSigned selfSigned;

  public static final String SERIALIZED_NAME_VAULT = "vault";
  @SerializedName(SERIALIZED_NAME_VAULT)
  private V1ClusterIssuerSpecVault vault;

  public static final String SERIALIZED_NAME_VENAFI = "venafi";
  @SerializedName(SERIALIZED_NAME_VENAFI)
  private V1ClusterIssuerSpecVenafi venafi;

  public V1IssuerSpec() {
  }

  public V1IssuerSpec acme(V1ClusterIssuerSpecAcme acme) {
    
    this.acme = acme;
    return this;
  }

   /**
   * Get acme
   * @return acme
  **/
  @jakarta.annotation.Nullable
  public V1ClusterIssuerSpecAcme getAcme() {
    return acme;
  }


  public void setAcme(V1ClusterIssuerSpecAcme acme) {
    this.acme = acme;
  }


  public V1IssuerSpec ca(V1ClusterIssuerSpecCa ca) {
    
    this.ca = ca;
    return this;
  }

   /**
   * Get ca
   * @return ca
  **/
  @jakarta.annotation.Nullable
  public V1ClusterIssuerSpecCa getCa() {
    return ca;
  }


  public void setCa(V1ClusterIssuerSpecCa ca) {
    this.ca = ca;
  }


  public V1IssuerSpec selfSigned(V1ClusterIssuerSpecSelfSigned selfSigned) {
    
    this.selfSigned = selfSigned;
    return this;
  }

   /**
   * Get selfSigned
   * @return selfSigned
  **/
  @jakarta.annotation.Nullable
  public V1ClusterIssuerSpecSelfSigned getSelfSigned() {
    return selfSigned;
  }


  public void setSelfSigned(V1ClusterIssuerSpecSelfSigned selfSigned) {
    this.selfSigned = selfSigned;
  }


  public V1IssuerSpec vault(V1ClusterIssuerSpecVault vault) {
    
    this.vault = vault;
    return this;
  }

   /**
   * Get vault
   * @return vault
  **/
  @jakarta.annotation.Nullable
  public V1ClusterIssuerSpecVault getVault() {
    return vault;
  }


  public void setVault(V1ClusterIssuerSpecVault vault) {
    this.vault = vault;
  }


  public V1IssuerSpec venafi(V1ClusterIssuerSpecVenafi venafi) {
    
    this.venafi = venafi;
    return this;
  }

   /**
   * Get venafi
   * @return venafi
  **/
  @jakarta.annotation.Nullable
  public V1ClusterIssuerSpecVenafi getVenafi() {
    return venafi;
  }


  public void setVenafi(V1ClusterIssuerSpecVenafi venafi) {
    this.venafi = venafi;
  }



  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    V1IssuerSpec v1IssuerSpec = (V1IssuerSpec) o;
    return Objects.equals(this.acme, v1IssuerSpec.acme) &&
        Objects.equals(this.ca, v1IssuerSpec.ca) &&
        Objects.equals(this.selfSigned, v1IssuerSpec.selfSigned) &&
        Objects.equals(this.vault, v1IssuerSpec.vault) &&
        Objects.equals(this.venafi, v1IssuerSpec.venafi);
  }

  @Override
  public int hashCode() {
    return Objects.hash(acme, ca, selfSigned, vault, venafi);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class V1IssuerSpec {\n");
    sb.append("    acme: ").append(toIndentedString(acme)).append("\n");
    sb.append("    ca: ").append(toIndentedString(ca)).append("\n");
    sb.append("    selfSigned: ").append(toIndentedString(selfSigned)).append("\n");
    sb.append("    vault: ").append(toIndentedString(vault)).append("\n");
    sb.append("    venafi: ").append(toIndentedString(venafi)).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("acme");
    openapiFields.add("ca");
    openapiFields.add("selfSigned");
    openapiFields.add("vault");
    openapiFields.add("venafi");

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

 /**
  * Validates the JSON Object and throws an exception if issues found
  *
  * @param jsonObj JSON Object
  * @throws IOException if the JSON Object is invalid with respect to V1IssuerSpec
  */
  public static void validateJsonObject(JsonObject jsonObj) throws IOException {
      if (jsonObj == null) {
        if (!V1IssuerSpec.openapiRequiredFields.isEmpty()) { // has required fields but JSON object is null
          throw new IllegalArgumentException(String.format("The required field(s) %s in V1IssuerSpec is not found in the empty JSON string", V1IssuerSpec.openapiRequiredFields.toString()));
        }
      }

      Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
      // check to see if the JSON string contains additional fields
      for (Entry<String, JsonElement> entry : entries) {
        if (!V1IssuerSpec.openapiFields.contains(entry.getKey())) {
          throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `V1IssuerSpec` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
        }
      }
      // validate the optional field `acme`
      if (jsonObj.get("acme") != null && !jsonObj.get("acme").isJsonNull()) {
        V1ClusterIssuerSpecAcme.validateJsonObject(jsonObj.getAsJsonObject("acme"));
      }
      // validate the optional field `ca`
      if (jsonObj.get("ca") != null && !jsonObj.get("ca").isJsonNull()) {
        V1ClusterIssuerSpecCa.validateJsonObject(jsonObj.getAsJsonObject("ca"));
      }
      // validate the optional field `selfSigned`
      if (jsonObj.get("selfSigned") != null && !jsonObj.get("selfSigned").isJsonNull()) {
        V1ClusterIssuerSpecSelfSigned.validateJsonObject(jsonObj.getAsJsonObject("selfSigned"));
      }
      // validate the optional field `vault`
      if (jsonObj.get("vault") != null && !jsonObj.get("vault").isJsonNull()) {
        V1ClusterIssuerSpecVault.validateJsonObject(jsonObj.getAsJsonObject("vault"));
      }
      // validate the optional field `venafi`
      if (jsonObj.get("venafi") != null && !jsonObj.get("venafi").isJsonNull()) {
        V1ClusterIssuerSpecVenafi.validateJsonObject(jsonObj.getAsJsonObject("venafi"));
      }
  }

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

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

           @Override
           public V1IssuerSpec read(JsonReader in) throws IOException {
             JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
             validateJsonObject(jsonObj);
             return thisAdapter.fromJsonTree(jsonObj);
           }

       }.nullSafe();
    }
  }

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

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

