/*
 * 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.V1ClusterIssuerSpecVaultAuth;
import io.cert.manager.models.V1ClusterIssuerSpecVaultCaBundleSecretRef;
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;

/**
 * Vault configures this issuer to sign certificates using a HashiCorp Vault PKI backend.
 */
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2024-03-01T07:00:20.132973Z[Etc/UTC]")
public class V1ClusterIssuerSpecVault {
  public static final String SERIALIZED_NAME_AUTH = "auth";
  @SerializedName(SERIALIZED_NAME_AUTH)
  private V1ClusterIssuerSpecVaultAuth auth;

  public static final String SERIALIZED_NAME_CA_BUNDLE = "caBundle";
  @SerializedName(SERIALIZED_NAME_CA_BUNDLE)
  private byte[] caBundle;

  public static final String SERIALIZED_NAME_CA_BUNDLE_SECRET_REF = "caBundleSecretRef";
  @SerializedName(SERIALIZED_NAME_CA_BUNDLE_SECRET_REF)
  private V1ClusterIssuerSpecVaultCaBundleSecretRef caBundleSecretRef;

  public static final String SERIALIZED_NAME_NAMESPACE = "namespace";
  @SerializedName(SERIALIZED_NAME_NAMESPACE)
  private String namespace;

  public static final String SERIALIZED_NAME_PATH = "path";
  @SerializedName(SERIALIZED_NAME_PATH)
  private String path;

  public static final String SERIALIZED_NAME_SERVER = "server";
  @SerializedName(SERIALIZED_NAME_SERVER)
  private String server;

  public V1ClusterIssuerSpecVault() {
  }

  public V1ClusterIssuerSpecVault auth(V1ClusterIssuerSpecVaultAuth auth) {
    
    this.auth = auth;
    return this;
  }

   /**
   * Get auth
   * @return auth
  **/
  @jakarta.annotation.Nonnull
  public V1ClusterIssuerSpecVaultAuth getAuth() {
    return auth;
  }


  public void setAuth(V1ClusterIssuerSpecVaultAuth auth) {
    this.auth = auth;
  }


  public V1ClusterIssuerSpecVault caBundle(byte[] caBundle) {
    
    this.caBundle = caBundle;
    return this;
  }

   /**
   * Base64-encoded bundle of PEM CAs which will be used to validate the certificate chain presented by Vault. Only used if using HTTPS to connect to Vault and ignored for HTTP connections. Mutually exclusive with CABundleSecretRef. If neither CABundle nor CABundleSecretRef are defined, the certificate bundle in the cert-manager controller container is used to validate the TLS connection.
   * @return caBundle
  **/
  @jakarta.annotation.Nullable
  public byte[] getCaBundle() {
    return caBundle;
  }


  public void setCaBundle(byte[] caBundle) {
    this.caBundle = caBundle;
  }


  public V1ClusterIssuerSpecVault caBundleSecretRef(V1ClusterIssuerSpecVaultCaBundleSecretRef caBundleSecretRef) {
    
    this.caBundleSecretRef = caBundleSecretRef;
    return this;
  }

   /**
   * Get caBundleSecretRef
   * @return caBundleSecretRef
  **/
  @jakarta.annotation.Nullable
  public V1ClusterIssuerSpecVaultCaBundleSecretRef getCaBundleSecretRef() {
    return caBundleSecretRef;
  }


  public void setCaBundleSecretRef(V1ClusterIssuerSpecVaultCaBundleSecretRef caBundleSecretRef) {
    this.caBundleSecretRef = caBundleSecretRef;
  }


  public V1ClusterIssuerSpecVault namespace(String namespace) {
    
    this.namespace = namespace;
    return this;
  }

   /**
   * Name of the vault namespace. Namespaces is a set of features within Vault Enterprise that allows Vault environments to support Secure Multi-tenancy. e.g: \&quot;ns1\&quot; More about namespaces can be found here https://www.vaultproject.io/docs/enterprise/namespaces
   * @return namespace
  **/
  @jakarta.annotation.Nullable
  public String getNamespace() {
    return namespace;
  }


  public void setNamespace(String namespace) {
    this.namespace = namespace;
  }


  public V1ClusterIssuerSpecVault path(String path) {
    
    this.path = path;
    return this;
  }

   /**
   * Path is the mount path of the Vault PKI backend&#39;s &#x60;sign&#x60; endpoint, e.g: \&quot;my_pki_mount/sign/my-role-name\&quot;.
   * @return path
  **/
  @jakarta.annotation.Nonnull
  public String getPath() {
    return path;
  }


  public void setPath(String path) {
    this.path = path;
  }


  public V1ClusterIssuerSpecVault server(String server) {
    
    this.server = server;
    return this;
  }

   /**
   * Server is the connection address for the Vault server, e.g: \&quot;https://vault.example.com:8200\&quot;.
   * @return server
  **/
  @jakarta.annotation.Nonnull
  public String getServer() {
    return server;
  }


  public void setServer(String server) {
    this.server = server;
  }



  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    V1ClusterIssuerSpecVault v1ClusterIssuerSpecVault = (V1ClusterIssuerSpecVault) o;
    return Objects.equals(this.auth, v1ClusterIssuerSpecVault.auth) &&
        Arrays.equals(this.caBundle, v1ClusterIssuerSpecVault.caBundle) &&
        Objects.equals(this.caBundleSecretRef, v1ClusterIssuerSpecVault.caBundleSecretRef) &&
        Objects.equals(this.namespace, v1ClusterIssuerSpecVault.namespace) &&
        Objects.equals(this.path, v1ClusterIssuerSpecVault.path) &&
        Objects.equals(this.server, v1ClusterIssuerSpecVault.server);
  }

  @Override
  public int hashCode() {
    return Objects.hash(auth, Arrays.hashCode(caBundle), caBundleSecretRef, namespace, path, server);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class V1ClusterIssuerSpecVault {\n");
    sb.append("    auth: ").append(toIndentedString(auth)).append("\n");
    sb.append("    caBundle: ").append(toIndentedString(caBundle)).append("\n");
    sb.append("    caBundleSecretRef: ").append(toIndentedString(caBundleSecretRef)).append("\n");
    sb.append("    namespace: ").append(toIndentedString(namespace)).append("\n");
    sb.append("    path: ").append(toIndentedString(path)).append("\n");
    sb.append("    server: ").append(toIndentedString(server)).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("auth");
    openapiFields.add("caBundle");
    openapiFields.add("caBundleSecretRef");
    openapiFields.add("namespace");
    openapiFields.add("path");
    openapiFields.add("server");

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

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

      // check to make sure all required properties/fields are present in the JSON string
      for (String requiredField : V1ClusterIssuerSpecVault.openapiRequiredFields) {
        if (jsonObj.get(requiredField) == null) {
          throw new IllegalArgumentException(String.format("The required field `%s` is not found in the JSON string: %s", requiredField, jsonObj.toString()));
        }
      }
      // validate the required field `auth`
      V1ClusterIssuerSpecVaultAuth.validateJsonObject(jsonObj.getAsJsonObject("auth"));
      // validate the optional field `caBundleSecretRef`
      if (jsonObj.get("caBundleSecretRef") != null && !jsonObj.get("caBundleSecretRef").isJsonNull()) {
        V1ClusterIssuerSpecVaultCaBundleSecretRef.validateJsonObject(jsonObj.getAsJsonObject("caBundleSecretRef"));
      }
      if ((jsonObj.get("namespace") != null && !jsonObj.get("namespace").isJsonNull()) && !jsonObj.get("namespace").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `namespace` to be a primitive type in the JSON string but got `%s`", jsonObj.get("namespace").toString()));
      }
      if (!jsonObj.get("path").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `path` to be a primitive type in the JSON string but got `%s`", jsonObj.get("path").toString()));
      }
      if (!jsonObj.get("server").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `server` to be a primitive type in the JSON string but got `%s`", jsonObj.get("server").toString()));
      }
  }

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

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

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

       }.nullSafe();
    }
  }

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

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

