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

/**
 * Kubernetes authenticates with Vault by passing the ServiceAccount token stored in the named Secret resource to the Vault server.
 */
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2024-03-01T07:00:20.132973Z[Etc/UTC]")
public class V1ClusterIssuerSpecVaultAuthKubernetes {
  public static final String SERIALIZED_NAME_MOUNT_PATH = "mountPath";
  @SerializedName(SERIALIZED_NAME_MOUNT_PATH)
  private String mountPath;

  public static final String SERIALIZED_NAME_ROLE = "role";
  @SerializedName(SERIALIZED_NAME_ROLE)
  private String role;

  public static final String SERIALIZED_NAME_SECRET_REF = "secretRef";
  @SerializedName(SERIALIZED_NAME_SECRET_REF)
  private V1ClusterIssuerSpecVaultAuthKubernetesSecretRef secretRef;

  public static final String SERIALIZED_NAME_SERVICE_ACCOUNT_REF = "serviceAccountRef";
  @SerializedName(SERIALIZED_NAME_SERVICE_ACCOUNT_REF)
  private V1ClusterIssuerSpecVaultAuthKubernetesServiceAccountRef serviceAccountRef;

  public V1ClusterIssuerSpecVaultAuthKubernetes() {
  }

  public V1ClusterIssuerSpecVaultAuthKubernetes mountPath(String mountPath) {
    
    this.mountPath = mountPath;
    return this;
  }

   /**
   * The Vault mountPath here is the mount path to use when authenticating with Vault. For example, setting a value to &#x60;/v1/auth/foo&#x60;, will use the path &#x60;/v1/auth/foo/login&#x60; to authenticate with Vault. If unspecified, the default value \&quot;/v1/auth/kubernetes\&quot; will be used.
   * @return mountPath
  **/
  @jakarta.annotation.Nullable
  public String getMountPath() {
    return mountPath;
  }


  public void setMountPath(String mountPath) {
    this.mountPath = mountPath;
  }


  public V1ClusterIssuerSpecVaultAuthKubernetes role(String role) {
    
    this.role = role;
    return this;
  }

   /**
   * A required field containing the Vault Role to assume. A Role binds a Kubernetes ServiceAccount with a set of Vault policies.
   * @return role
  **/
  @jakarta.annotation.Nonnull
  public String getRole() {
    return role;
  }


  public void setRole(String role) {
    this.role = role;
  }


  public V1ClusterIssuerSpecVaultAuthKubernetes secretRef(V1ClusterIssuerSpecVaultAuthKubernetesSecretRef secretRef) {
    
    this.secretRef = secretRef;
    return this;
  }

   /**
   * Get secretRef
   * @return secretRef
  **/
  @jakarta.annotation.Nullable
  public V1ClusterIssuerSpecVaultAuthKubernetesSecretRef getSecretRef() {
    return secretRef;
  }


  public void setSecretRef(V1ClusterIssuerSpecVaultAuthKubernetesSecretRef secretRef) {
    this.secretRef = secretRef;
  }


  public V1ClusterIssuerSpecVaultAuthKubernetes serviceAccountRef(V1ClusterIssuerSpecVaultAuthKubernetesServiceAccountRef serviceAccountRef) {
    
    this.serviceAccountRef = serviceAccountRef;
    return this;
  }

   /**
   * Get serviceAccountRef
   * @return serviceAccountRef
  **/
  @jakarta.annotation.Nullable
  public V1ClusterIssuerSpecVaultAuthKubernetesServiceAccountRef getServiceAccountRef() {
    return serviceAccountRef;
  }


  public void setServiceAccountRef(V1ClusterIssuerSpecVaultAuthKubernetesServiceAccountRef serviceAccountRef) {
    this.serviceAccountRef = serviceAccountRef;
  }



  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    V1ClusterIssuerSpecVaultAuthKubernetes v1ClusterIssuerSpecVaultAuthKubernetes = (V1ClusterIssuerSpecVaultAuthKubernetes) o;
    return Objects.equals(this.mountPath, v1ClusterIssuerSpecVaultAuthKubernetes.mountPath) &&
        Objects.equals(this.role, v1ClusterIssuerSpecVaultAuthKubernetes.role) &&
        Objects.equals(this.secretRef, v1ClusterIssuerSpecVaultAuthKubernetes.secretRef) &&
        Objects.equals(this.serviceAccountRef, v1ClusterIssuerSpecVaultAuthKubernetes.serviceAccountRef);
  }

  @Override
  public int hashCode() {
    return Objects.hash(mountPath, role, secretRef, serviceAccountRef);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class V1ClusterIssuerSpecVaultAuthKubernetes {\n");
    sb.append("    mountPath: ").append(toIndentedString(mountPath)).append("\n");
    sb.append("    role: ").append(toIndentedString(role)).append("\n");
    sb.append("    secretRef: ").append(toIndentedString(secretRef)).append("\n");
    sb.append("    serviceAccountRef: ").append(toIndentedString(serviceAccountRef)).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("mountPath");
    openapiFields.add("role");
    openapiFields.add("secretRef");
    openapiFields.add("serviceAccountRef");

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

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

      // check to make sure all required properties/fields are present in the JSON string
      for (String requiredField : V1ClusterIssuerSpecVaultAuthKubernetes.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()));
        }
      }
      if ((jsonObj.get("mountPath") != null && !jsonObj.get("mountPath").isJsonNull()) && !jsonObj.get("mountPath").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `mountPath` to be a primitive type in the JSON string but got `%s`", jsonObj.get("mountPath").toString()));
      }
      if (!jsonObj.get("role").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `role` to be a primitive type in the JSON string but got `%s`", jsonObj.get("role").toString()));
      }
      // validate the optional field `secretRef`
      if (jsonObj.get("secretRef") != null && !jsonObj.get("secretRef").isJsonNull()) {
        V1ClusterIssuerSpecVaultAuthKubernetesSecretRef.validateJsonObject(jsonObj.getAsJsonObject("secretRef"));
      }
      // validate the optional field `serviceAccountRef`
      if (jsonObj.get("serviceAccountRef") != null && !jsonObj.get("serviceAccountRef").isJsonNull()) {
        V1ClusterIssuerSpecVaultAuthKubernetesServiceAccountRef.validateJsonObject(jsonObj.getAsJsonObject("serviceAccountRef"));
      }
  }

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

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

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

       }.nullSafe();
    }
  }

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

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

