/*
 * 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.V1ChallengeSpecSolverDns01AcmeDNS;
import io.cert.manager.models.V1ChallengeSpecSolverDns01Akamai;
import io.cert.manager.models.V1ChallengeSpecSolverDns01AzureDNS;
import io.cert.manager.models.V1ChallengeSpecSolverDns01CloudDNS;
import io.cert.manager.models.V1ChallengeSpecSolverDns01Cloudflare;
import io.cert.manager.models.V1ChallengeSpecSolverDns01Digitalocean;
import io.cert.manager.models.V1ChallengeSpecSolverDns01Rfc2136;
import io.cert.manager.models.V1ChallengeSpecSolverDns01Route53;
import io.cert.manager.models.V1ChallengeSpecSolverDns01Webhook;
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;

/**
 * Configures cert-manager to attempt to complete authorizations by performing the DNS01 challenge flow.
 */
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2024-03-01T07:00:20.132973Z[Etc/UTC]")
public class V1ChallengeSpecSolverDns01 {
  public static final String SERIALIZED_NAME_ACME_D_N_S = "acmeDNS";
  @SerializedName(SERIALIZED_NAME_ACME_D_N_S)
  private V1ChallengeSpecSolverDns01AcmeDNS acmeDNS;

  public static final String SERIALIZED_NAME_AKAMAI = "akamai";
  @SerializedName(SERIALIZED_NAME_AKAMAI)
  private V1ChallengeSpecSolverDns01Akamai akamai;

  public static final String SERIALIZED_NAME_AZURE_D_N_S = "azureDNS";
  @SerializedName(SERIALIZED_NAME_AZURE_D_N_S)
  private V1ChallengeSpecSolverDns01AzureDNS azureDNS;

  public static final String SERIALIZED_NAME_CLOUD_D_N_S = "cloudDNS";
  @SerializedName(SERIALIZED_NAME_CLOUD_D_N_S)
  private V1ChallengeSpecSolverDns01CloudDNS cloudDNS;

  public static final String SERIALIZED_NAME_CLOUDFLARE = "cloudflare";
  @SerializedName(SERIALIZED_NAME_CLOUDFLARE)
  private V1ChallengeSpecSolverDns01Cloudflare cloudflare;

  /**
   * CNAMEStrategy configures how the DNS01 provider should handle CNAME records when found in DNS zones.
   */
  @JsonAdapter(CnameStrategyEnum.Adapter.class)
  public enum CnameStrategyEnum {
    NONE("None"),
    
    FOLLOW("Follow");

    private String value;

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

    public String getValue() {
      return value;
    }

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

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

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

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

  public static final String SERIALIZED_NAME_CNAME_STRATEGY = "cnameStrategy";
  @SerializedName(SERIALIZED_NAME_CNAME_STRATEGY)
  private CnameStrategyEnum cnameStrategy;

  public static final String SERIALIZED_NAME_DIGITALOCEAN = "digitalocean";
  @SerializedName(SERIALIZED_NAME_DIGITALOCEAN)
  private V1ChallengeSpecSolverDns01Digitalocean digitalocean;

  public static final String SERIALIZED_NAME_RFC2136 = "rfc2136";
  @SerializedName(SERIALIZED_NAME_RFC2136)
  private V1ChallengeSpecSolverDns01Rfc2136 rfc2136;

  public static final String SERIALIZED_NAME_ROUTE53 = "route53";
  @SerializedName(SERIALIZED_NAME_ROUTE53)
  private V1ChallengeSpecSolverDns01Route53 route53;

  public static final String SERIALIZED_NAME_WEBHOOK = "webhook";
  @SerializedName(SERIALIZED_NAME_WEBHOOK)
  private V1ChallengeSpecSolverDns01Webhook webhook;

  public V1ChallengeSpecSolverDns01() {
  }

  public V1ChallengeSpecSolverDns01 acmeDNS(V1ChallengeSpecSolverDns01AcmeDNS acmeDNS) {
    
    this.acmeDNS = acmeDNS;
    return this;
  }

   /**
   * Get acmeDNS
   * @return acmeDNS
  **/
  @jakarta.annotation.Nullable
  public V1ChallengeSpecSolverDns01AcmeDNS getAcmeDNS() {
    return acmeDNS;
  }


  public void setAcmeDNS(V1ChallengeSpecSolverDns01AcmeDNS acmeDNS) {
    this.acmeDNS = acmeDNS;
  }


  public V1ChallengeSpecSolverDns01 akamai(V1ChallengeSpecSolverDns01Akamai akamai) {
    
    this.akamai = akamai;
    return this;
  }

   /**
   * Get akamai
   * @return akamai
  **/
  @jakarta.annotation.Nullable
  public V1ChallengeSpecSolverDns01Akamai getAkamai() {
    return akamai;
  }


  public void setAkamai(V1ChallengeSpecSolverDns01Akamai akamai) {
    this.akamai = akamai;
  }


  public V1ChallengeSpecSolverDns01 azureDNS(V1ChallengeSpecSolverDns01AzureDNS azureDNS) {
    
    this.azureDNS = azureDNS;
    return this;
  }

   /**
   * Get azureDNS
   * @return azureDNS
  **/
  @jakarta.annotation.Nullable
  public V1ChallengeSpecSolverDns01AzureDNS getAzureDNS() {
    return azureDNS;
  }


  public void setAzureDNS(V1ChallengeSpecSolverDns01AzureDNS azureDNS) {
    this.azureDNS = azureDNS;
  }


  public V1ChallengeSpecSolverDns01 cloudDNS(V1ChallengeSpecSolverDns01CloudDNS cloudDNS) {
    
    this.cloudDNS = cloudDNS;
    return this;
  }

   /**
   * Get cloudDNS
   * @return cloudDNS
  **/
  @jakarta.annotation.Nullable
  public V1ChallengeSpecSolverDns01CloudDNS getCloudDNS() {
    return cloudDNS;
  }


  public void setCloudDNS(V1ChallengeSpecSolverDns01CloudDNS cloudDNS) {
    this.cloudDNS = cloudDNS;
  }


  public V1ChallengeSpecSolverDns01 cloudflare(V1ChallengeSpecSolverDns01Cloudflare cloudflare) {
    
    this.cloudflare = cloudflare;
    return this;
  }

   /**
   * Get cloudflare
   * @return cloudflare
  **/
  @jakarta.annotation.Nullable
  public V1ChallengeSpecSolverDns01Cloudflare getCloudflare() {
    return cloudflare;
  }


  public void setCloudflare(V1ChallengeSpecSolverDns01Cloudflare cloudflare) {
    this.cloudflare = cloudflare;
  }


  public V1ChallengeSpecSolverDns01 cnameStrategy(CnameStrategyEnum cnameStrategy) {
    
    this.cnameStrategy = cnameStrategy;
    return this;
  }

   /**
   * CNAMEStrategy configures how the DNS01 provider should handle CNAME records when found in DNS zones.
   * @return cnameStrategy
  **/
  @jakarta.annotation.Nullable
  public CnameStrategyEnum getCnameStrategy() {
    return cnameStrategy;
  }


  public void setCnameStrategy(CnameStrategyEnum cnameStrategy) {
    this.cnameStrategy = cnameStrategy;
  }


  public V1ChallengeSpecSolverDns01 digitalocean(V1ChallengeSpecSolverDns01Digitalocean digitalocean) {
    
    this.digitalocean = digitalocean;
    return this;
  }

   /**
   * Get digitalocean
   * @return digitalocean
  **/
  @jakarta.annotation.Nullable
  public V1ChallengeSpecSolverDns01Digitalocean getDigitalocean() {
    return digitalocean;
  }


  public void setDigitalocean(V1ChallengeSpecSolverDns01Digitalocean digitalocean) {
    this.digitalocean = digitalocean;
  }


  public V1ChallengeSpecSolverDns01 rfc2136(V1ChallengeSpecSolverDns01Rfc2136 rfc2136) {
    
    this.rfc2136 = rfc2136;
    return this;
  }

   /**
   * Get rfc2136
   * @return rfc2136
  **/
  @jakarta.annotation.Nullable
  public V1ChallengeSpecSolverDns01Rfc2136 getRfc2136() {
    return rfc2136;
  }


  public void setRfc2136(V1ChallengeSpecSolverDns01Rfc2136 rfc2136) {
    this.rfc2136 = rfc2136;
  }


  public V1ChallengeSpecSolverDns01 route53(V1ChallengeSpecSolverDns01Route53 route53) {
    
    this.route53 = route53;
    return this;
  }

   /**
   * Get route53
   * @return route53
  **/
  @jakarta.annotation.Nullable
  public V1ChallengeSpecSolverDns01Route53 getRoute53() {
    return route53;
  }


  public void setRoute53(V1ChallengeSpecSolverDns01Route53 route53) {
    this.route53 = route53;
  }


  public V1ChallengeSpecSolverDns01 webhook(V1ChallengeSpecSolverDns01Webhook webhook) {
    
    this.webhook = webhook;
    return this;
  }

   /**
   * Get webhook
   * @return webhook
  **/
  @jakarta.annotation.Nullable
  public V1ChallengeSpecSolverDns01Webhook getWebhook() {
    return webhook;
  }


  public void setWebhook(V1ChallengeSpecSolverDns01Webhook webhook) {
    this.webhook = webhook;
  }



  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    V1ChallengeSpecSolverDns01 v1ChallengeSpecSolverDns01 = (V1ChallengeSpecSolverDns01) o;
    return Objects.equals(this.acmeDNS, v1ChallengeSpecSolverDns01.acmeDNS) &&
        Objects.equals(this.akamai, v1ChallengeSpecSolverDns01.akamai) &&
        Objects.equals(this.azureDNS, v1ChallengeSpecSolverDns01.azureDNS) &&
        Objects.equals(this.cloudDNS, v1ChallengeSpecSolverDns01.cloudDNS) &&
        Objects.equals(this.cloudflare, v1ChallengeSpecSolverDns01.cloudflare) &&
        Objects.equals(this.cnameStrategy, v1ChallengeSpecSolverDns01.cnameStrategy) &&
        Objects.equals(this.digitalocean, v1ChallengeSpecSolverDns01.digitalocean) &&
        Objects.equals(this.rfc2136, v1ChallengeSpecSolverDns01.rfc2136) &&
        Objects.equals(this.route53, v1ChallengeSpecSolverDns01.route53) &&
        Objects.equals(this.webhook, v1ChallengeSpecSolverDns01.webhook);
  }

  @Override
  public int hashCode() {
    return Objects.hash(acmeDNS, akamai, azureDNS, cloudDNS, cloudflare, cnameStrategy, digitalocean, rfc2136, route53, webhook);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class V1ChallengeSpecSolverDns01 {\n");
    sb.append("    acmeDNS: ").append(toIndentedString(acmeDNS)).append("\n");
    sb.append("    akamai: ").append(toIndentedString(akamai)).append("\n");
    sb.append("    azureDNS: ").append(toIndentedString(azureDNS)).append("\n");
    sb.append("    cloudDNS: ").append(toIndentedString(cloudDNS)).append("\n");
    sb.append("    cloudflare: ").append(toIndentedString(cloudflare)).append("\n");
    sb.append("    cnameStrategy: ").append(toIndentedString(cnameStrategy)).append("\n");
    sb.append("    digitalocean: ").append(toIndentedString(digitalocean)).append("\n");
    sb.append("    rfc2136: ").append(toIndentedString(rfc2136)).append("\n");
    sb.append("    route53: ").append(toIndentedString(route53)).append("\n");
    sb.append("    webhook: ").append(toIndentedString(webhook)).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("acmeDNS");
    openapiFields.add("akamai");
    openapiFields.add("azureDNS");
    openapiFields.add("cloudDNS");
    openapiFields.add("cloudflare");
    openapiFields.add("cnameStrategy");
    openapiFields.add("digitalocean");
    openapiFields.add("rfc2136");
    openapiFields.add("route53");
    openapiFields.add("webhook");

    // 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 V1ChallengeSpecSolverDns01
  */
  public static void validateJsonObject(JsonObject jsonObj) throws IOException {
      if (jsonObj == null) {
        if (!V1ChallengeSpecSolverDns01.openapiRequiredFields.isEmpty()) { // has required fields but JSON object is null
          throw new IllegalArgumentException(String.format("The required field(s) %s in V1ChallengeSpecSolverDns01 is not found in the empty JSON string", V1ChallengeSpecSolverDns01.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 (!V1ChallengeSpecSolverDns01.openapiFields.contains(entry.getKey())) {
          throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `V1ChallengeSpecSolverDns01` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
        }
      }
      // validate the optional field `acmeDNS`
      if (jsonObj.get("acmeDNS") != null && !jsonObj.get("acmeDNS").isJsonNull()) {
        V1ChallengeSpecSolverDns01AcmeDNS.validateJsonObject(jsonObj.getAsJsonObject("acmeDNS"));
      }
      // validate the optional field `akamai`
      if (jsonObj.get("akamai") != null && !jsonObj.get("akamai").isJsonNull()) {
        V1ChallengeSpecSolverDns01Akamai.validateJsonObject(jsonObj.getAsJsonObject("akamai"));
      }
      // validate the optional field `azureDNS`
      if (jsonObj.get("azureDNS") != null && !jsonObj.get("azureDNS").isJsonNull()) {
        V1ChallengeSpecSolverDns01AzureDNS.validateJsonObject(jsonObj.getAsJsonObject("azureDNS"));
      }
      // validate the optional field `cloudDNS`
      if (jsonObj.get("cloudDNS") != null && !jsonObj.get("cloudDNS").isJsonNull()) {
        V1ChallengeSpecSolverDns01CloudDNS.validateJsonObject(jsonObj.getAsJsonObject("cloudDNS"));
      }
      // validate the optional field `cloudflare`
      if (jsonObj.get("cloudflare") != null && !jsonObj.get("cloudflare").isJsonNull()) {
        V1ChallengeSpecSolverDns01Cloudflare.validateJsonObject(jsonObj.getAsJsonObject("cloudflare"));
      }
      if ((jsonObj.get("cnameStrategy") != null && !jsonObj.get("cnameStrategy").isJsonNull()) && !jsonObj.get("cnameStrategy").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `cnameStrategy` to be a primitive type in the JSON string but got `%s`", jsonObj.get("cnameStrategy").toString()));
      }
      // validate the optional field `digitalocean`
      if (jsonObj.get("digitalocean") != null && !jsonObj.get("digitalocean").isJsonNull()) {
        V1ChallengeSpecSolverDns01Digitalocean.validateJsonObject(jsonObj.getAsJsonObject("digitalocean"));
      }
      // validate the optional field `rfc2136`
      if (jsonObj.get("rfc2136") != null && !jsonObj.get("rfc2136").isJsonNull()) {
        V1ChallengeSpecSolverDns01Rfc2136.validateJsonObject(jsonObj.getAsJsonObject("rfc2136"));
      }
      // validate the optional field `route53`
      if (jsonObj.get("route53") != null && !jsonObj.get("route53").isJsonNull()) {
        V1ChallengeSpecSolverDns01Route53.validateJsonObject(jsonObj.getAsJsonObject("route53"));
      }
      // validate the optional field `webhook`
      if (jsonObj.get("webhook") != null && !jsonObj.get("webhook").isJsonNull()) {
        V1ChallengeSpecSolverDns01Webhook.validateJsonObject(jsonObj.getAsJsonObject("webhook"));
      }
  }

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

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

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

       }.nullSafe();
    }
  }

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

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

