/*
 * 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.V1ChallengeSpecSolverHttp01IngressPodTemplateSpecAffinity;
import io.cert.manager.models.V1ChallengeSpecSolverHttp01IngressPodTemplateSpecImagePullSecretsInner;
import io.cert.manager.models.V1ChallengeSpecSolverHttp01IngressPodTemplateSpecTolerationsInner;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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;

/**
 * PodSpec defines overrides for the HTTP01 challenge solver pod. Check ACMEChallengeSolverHTTP01IngressPodSpec to find out currently supported fields. All other fields will be ignored.
 */
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2024-03-01T07:00:20.132973Z[Etc/UTC]")
public class V1ChallengeSpecSolverHttp01IngressPodTemplateSpec {
  public static final String SERIALIZED_NAME_AFFINITY = "affinity";
  @SerializedName(SERIALIZED_NAME_AFFINITY)
  private V1ChallengeSpecSolverHttp01IngressPodTemplateSpecAffinity affinity;

  public static final String SERIALIZED_NAME_IMAGE_PULL_SECRETS = "imagePullSecrets";
  @SerializedName(SERIALIZED_NAME_IMAGE_PULL_SECRETS)
  private List<V1ChallengeSpecSolverHttp01IngressPodTemplateSpecImagePullSecretsInner> imagePullSecrets;

  public static final String SERIALIZED_NAME_NODE_SELECTOR = "nodeSelector";
  @SerializedName(SERIALIZED_NAME_NODE_SELECTOR)
  private Map<String, String> nodeSelector = new HashMap<>();

  public static final String SERIALIZED_NAME_PRIORITY_CLASS_NAME = "priorityClassName";
  @SerializedName(SERIALIZED_NAME_PRIORITY_CLASS_NAME)
  private String priorityClassName;

  public static final String SERIALIZED_NAME_SERVICE_ACCOUNT_NAME = "serviceAccountName";
  @SerializedName(SERIALIZED_NAME_SERVICE_ACCOUNT_NAME)
  private String serviceAccountName;

  public static final String SERIALIZED_NAME_TOLERATIONS = "tolerations";
  @SerializedName(SERIALIZED_NAME_TOLERATIONS)
  private List<V1ChallengeSpecSolverHttp01IngressPodTemplateSpecTolerationsInner> tolerations;

  public V1ChallengeSpecSolverHttp01IngressPodTemplateSpec() {
  }

  public V1ChallengeSpecSolverHttp01IngressPodTemplateSpec affinity(V1ChallengeSpecSolverHttp01IngressPodTemplateSpecAffinity affinity) {
    
    this.affinity = affinity;
    return this;
  }

   /**
   * Get affinity
   * @return affinity
  **/
  @jakarta.annotation.Nullable
  public V1ChallengeSpecSolverHttp01IngressPodTemplateSpecAffinity getAffinity() {
    return affinity;
  }


  public void setAffinity(V1ChallengeSpecSolverHttp01IngressPodTemplateSpecAffinity affinity) {
    this.affinity = affinity;
  }


  public V1ChallengeSpecSolverHttp01IngressPodTemplateSpec imagePullSecrets(List<V1ChallengeSpecSolverHttp01IngressPodTemplateSpecImagePullSecretsInner> imagePullSecrets) {
    
    this.imagePullSecrets = imagePullSecrets;
    return this;
  }

  public V1ChallengeSpecSolverHttp01IngressPodTemplateSpec addImagePullSecretsItem(V1ChallengeSpecSolverHttp01IngressPodTemplateSpecImagePullSecretsInner imagePullSecretsItem) {
    if (this.imagePullSecrets == null) {
      this.imagePullSecrets = new ArrayList<>();
    }
    this.imagePullSecrets.add(imagePullSecretsItem);
    return this;
  }

   /**
   * If specified, the pod&#39;s imagePullSecrets
   * @return imagePullSecrets
  **/
  @jakarta.annotation.Nullable
  public List<V1ChallengeSpecSolverHttp01IngressPodTemplateSpecImagePullSecretsInner> getImagePullSecrets() {
    return imagePullSecrets;
  }


  public void setImagePullSecrets(List<V1ChallengeSpecSolverHttp01IngressPodTemplateSpecImagePullSecretsInner> imagePullSecrets) {
    this.imagePullSecrets = imagePullSecrets;
  }


  public V1ChallengeSpecSolverHttp01IngressPodTemplateSpec nodeSelector(Map<String, String> nodeSelector) {
    
    this.nodeSelector = nodeSelector;
    return this;
  }

  public V1ChallengeSpecSolverHttp01IngressPodTemplateSpec putNodeSelectorItem(String key, String nodeSelectorItem) {
    if (this.nodeSelector == null) {
      this.nodeSelector = new HashMap<>();
    }
    this.nodeSelector.put(key, nodeSelectorItem);
    return this;
  }

   /**
   * NodeSelector is a selector which must be true for the pod to fit on a node. Selector which must match a node&#39;s labels for the pod to be scheduled on that node. More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
   * @return nodeSelector
  **/
  @jakarta.annotation.Nullable
  public Map<String, String> getNodeSelector() {
    return nodeSelector;
  }


  public void setNodeSelector(Map<String, String> nodeSelector) {
    this.nodeSelector = nodeSelector;
  }


  public V1ChallengeSpecSolverHttp01IngressPodTemplateSpec priorityClassName(String priorityClassName) {
    
    this.priorityClassName = priorityClassName;
    return this;
  }

   /**
   * If specified, the pod&#39;s priorityClassName.
   * @return priorityClassName
  **/
  @jakarta.annotation.Nullable
  public String getPriorityClassName() {
    return priorityClassName;
  }


  public void setPriorityClassName(String priorityClassName) {
    this.priorityClassName = priorityClassName;
  }


  public V1ChallengeSpecSolverHttp01IngressPodTemplateSpec serviceAccountName(String serviceAccountName) {
    
    this.serviceAccountName = serviceAccountName;
    return this;
  }

   /**
   * If specified, the pod&#39;s service account
   * @return serviceAccountName
  **/
  @jakarta.annotation.Nullable
  public String getServiceAccountName() {
    return serviceAccountName;
  }


  public void setServiceAccountName(String serviceAccountName) {
    this.serviceAccountName = serviceAccountName;
  }


  public V1ChallengeSpecSolverHttp01IngressPodTemplateSpec tolerations(List<V1ChallengeSpecSolverHttp01IngressPodTemplateSpecTolerationsInner> tolerations) {
    
    this.tolerations = tolerations;
    return this;
  }

  public V1ChallengeSpecSolverHttp01IngressPodTemplateSpec addTolerationsItem(V1ChallengeSpecSolverHttp01IngressPodTemplateSpecTolerationsInner tolerationsItem) {
    if (this.tolerations == null) {
      this.tolerations = new ArrayList<>();
    }
    this.tolerations.add(tolerationsItem);
    return this;
  }

   /**
   * If specified, the pod&#39;s tolerations.
   * @return tolerations
  **/
  @jakarta.annotation.Nullable
  public List<V1ChallengeSpecSolverHttp01IngressPodTemplateSpecTolerationsInner> getTolerations() {
    return tolerations;
  }


  public void setTolerations(List<V1ChallengeSpecSolverHttp01IngressPodTemplateSpecTolerationsInner> tolerations) {
    this.tolerations = tolerations;
  }



  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    V1ChallengeSpecSolverHttp01IngressPodTemplateSpec v1ChallengeSpecSolverHttp01IngressPodTemplateSpec = (V1ChallengeSpecSolverHttp01IngressPodTemplateSpec) o;
    return Objects.equals(this.affinity, v1ChallengeSpecSolverHttp01IngressPodTemplateSpec.affinity) &&
        Objects.equals(this.imagePullSecrets, v1ChallengeSpecSolverHttp01IngressPodTemplateSpec.imagePullSecrets) &&
        Objects.equals(this.nodeSelector, v1ChallengeSpecSolverHttp01IngressPodTemplateSpec.nodeSelector) &&
        Objects.equals(this.priorityClassName, v1ChallengeSpecSolverHttp01IngressPodTemplateSpec.priorityClassName) &&
        Objects.equals(this.serviceAccountName, v1ChallengeSpecSolverHttp01IngressPodTemplateSpec.serviceAccountName) &&
        Objects.equals(this.tolerations, v1ChallengeSpecSolverHttp01IngressPodTemplateSpec.tolerations);
  }

  @Override
  public int hashCode() {
    return Objects.hash(affinity, imagePullSecrets, nodeSelector, priorityClassName, serviceAccountName, tolerations);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class V1ChallengeSpecSolverHttp01IngressPodTemplateSpec {\n");
    sb.append("    affinity: ").append(toIndentedString(affinity)).append("\n");
    sb.append("    imagePullSecrets: ").append(toIndentedString(imagePullSecrets)).append("\n");
    sb.append("    nodeSelector: ").append(toIndentedString(nodeSelector)).append("\n");
    sb.append("    priorityClassName: ").append(toIndentedString(priorityClassName)).append("\n");
    sb.append("    serviceAccountName: ").append(toIndentedString(serviceAccountName)).append("\n");
    sb.append("    tolerations: ").append(toIndentedString(tolerations)).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("affinity");
    openapiFields.add("imagePullSecrets");
    openapiFields.add("nodeSelector");
    openapiFields.add("priorityClassName");
    openapiFields.add("serviceAccountName");
    openapiFields.add("tolerations");

    // 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 V1ChallengeSpecSolverHttp01IngressPodTemplateSpec
  */
  public static void validateJsonObject(JsonObject jsonObj) throws IOException {
      if (jsonObj == null) {
        if (!V1ChallengeSpecSolverHttp01IngressPodTemplateSpec.openapiRequiredFields.isEmpty()) { // has required fields but JSON object is null
          throw new IllegalArgumentException(String.format("The required field(s) %s in V1ChallengeSpecSolverHttp01IngressPodTemplateSpec is not found in the empty JSON string", V1ChallengeSpecSolverHttp01IngressPodTemplateSpec.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 (!V1ChallengeSpecSolverHttp01IngressPodTemplateSpec.openapiFields.contains(entry.getKey())) {
          throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `V1ChallengeSpecSolverHttp01IngressPodTemplateSpec` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
        }
      }
      // validate the optional field `affinity`
      if (jsonObj.get("affinity") != null && !jsonObj.get("affinity").isJsonNull()) {
        V1ChallengeSpecSolverHttp01IngressPodTemplateSpecAffinity.validateJsonObject(jsonObj.getAsJsonObject("affinity"));
      }
      if (jsonObj.get("imagePullSecrets") != null && !jsonObj.get("imagePullSecrets").isJsonNull()) {
        JsonArray jsonArrayimagePullSecrets = jsonObj.getAsJsonArray("imagePullSecrets");
        if (jsonArrayimagePullSecrets != null) {
          // ensure the json data is an array
          if (!jsonObj.get("imagePullSecrets").isJsonArray()) {
            throw new IllegalArgumentException(String.format("Expected the field `imagePullSecrets` to be an array in the JSON string but got `%s`", jsonObj.get("imagePullSecrets").toString()));
          }

          // validate the optional field `imagePullSecrets` (array)
          for (int i = 0; i < jsonArrayimagePullSecrets.size(); i++) {
            V1ChallengeSpecSolverHttp01IngressPodTemplateSpecImagePullSecretsInner.validateJsonObject(jsonArrayimagePullSecrets.get(i).getAsJsonObject());
          };
        }
      }
      if ((jsonObj.get("priorityClassName") != null && !jsonObj.get("priorityClassName").isJsonNull()) && !jsonObj.get("priorityClassName").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `priorityClassName` to be a primitive type in the JSON string but got `%s`", jsonObj.get("priorityClassName").toString()));
      }
      if ((jsonObj.get("serviceAccountName") != null && !jsonObj.get("serviceAccountName").isJsonNull()) && !jsonObj.get("serviceAccountName").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `serviceAccountName` to be a primitive type in the JSON string but got `%s`", jsonObj.get("serviceAccountName").toString()));
      }
      if (jsonObj.get("tolerations") != null && !jsonObj.get("tolerations").isJsonNull()) {
        JsonArray jsonArraytolerations = jsonObj.getAsJsonArray("tolerations");
        if (jsonArraytolerations != null) {
          // ensure the json data is an array
          if (!jsonObj.get("tolerations").isJsonArray()) {
            throw new IllegalArgumentException(String.format("Expected the field `tolerations` to be an array in the JSON string but got `%s`", jsonObj.get("tolerations").toString()));
          }

          // validate the optional field `tolerations` (array)
          for (int i = 0; i < jsonArraytolerations.size(); i++) {
            V1ChallengeSpecSolverHttp01IngressPodTemplateSpecTolerationsInner.validateJsonObject(jsonArraytolerations.get(i).getAsJsonObject());
          };
        }
      }
  }

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

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

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

       }.nullSafe();
    }
  }

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

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

