/*
 * 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.V1OrderStatusAuthorizationsInnerChallengesInner;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

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;

/**
 * ACMEAuthorization contains data returned from the ACME server on an authorization that must be completed in order validate a DNS name on an ACME Order resource.
 */
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2024-03-01T07:00:20.132973Z[Etc/UTC]")
public class V1OrderStatusAuthorizationsInner {
  public static final String SERIALIZED_NAME_CHALLENGES = "challenges";
  @SerializedName(SERIALIZED_NAME_CHALLENGES)
  private List<V1OrderStatusAuthorizationsInnerChallengesInner> challenges;

  public static final String SERIALIZED_NAME_IDENTIFIER = "identifier";
  @SerializedName(SERIALIZED_NAME_IDENTIFIER)
  private String identifier;

  /**
   * InitialState is the initial state of the ACME authorization when first fetched from the ACME server. If an Authorization is already &#39;valid&#39;, the Order controller will not create a Challenge resource for the authorization. This will occur when working with an ACME server that enables &#39;authz reuse&#39; (such as Let&#39;s Encrypt&#39;s production endpoint). If not set and &#39;identifier&#39; is set, the state is assumed to be pending and a Challenge will be created.
   */
  @JsonAdapter(InitialStateEnum.Adapter.class)
  public enum InitialStateEnum {
    VALID("valid"),
    
    READY("ready"),
    
    PENDING("pending"),
    
    PROCESSING("processing"),
    
    INVALID("invalid"),
    
    EXPIRED("expired"),
    
    ERRORED("errored");

    private String value;

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

    public String getValue() {
      return value;
    }

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

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

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

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

  public static final String SERIALIZED_NAME_INITIAL_STATE = "initialState";
  @SerializedName(SERIALIZED_NAME_INITIAL_STATE)
  private InitialStateEnum initialState;

  public static final String SERIALIZED_NAME_URL = "url";
  @SerializedName(SERIALIZED_NAME_URL)
  private String url;

  public static final String SERIALIZED_NAME_WILDCARD = "wildcard";
  @SerializedName(SERIALIZED_NAME_WILDCARD)
  private Boolean wildcard;

  public V1OrderStatusAuthorizationsInner() {
  }

  public V1OrderStatusAuthorizationsInner challenges(List<V1OrderStatusAuthorizationsInnerChallengesInner> challenges) {
    
    this.challenges = challenges;
    return this;
  }

  public V1OrderStatusAuthorizationsInner addChallengesItem(V1OrderStatusAuthorizationsInnerChallengesInner challengesItem) {
    if (this.challenges == null) {
      this.challenges = new ArrayList<>();
    }
    this.challenges.add(challengesItem);
    return this;
  }

   /**
   * Challenges specifies the challenge types offered by the ACME server. One of these challenge types will be selected when validating the DNS name and an appropriate Challenge resource will be created to perform the ACME challenge process.
   * @return challenges
  **/
  @jakarta.annotation.Nullable
  public List<V1OrderStatusAuthorizationsInnerChallengesInner> getChallenges() {
    return challenges;
  }


  public void setChallenges(List<V1OrderStatusAuthorizationsInnerChallengesInner> challenges) {
    this.challenges = challenges;
  }


  public V1OrderStatusAuthorizationsInner identifier(String identifier) {
    
    this.identifier = identifier;
    return this;
  }

   /**
   * Identifier is the DNS name to be validated as part of this authorization
   * @return identifier
  **/
  @jakarta.annotation.Nullable
  public String getIdentifier() {
    return identifier;
  }


  public void setIdentifier(String identifier) {
    this.identifier = identifier;
  }


  public V1OrderStatusAuthorizationsInner initialState(InitialStateEnum initialState) {
    
    this.initialState = initialState;
    return this;
  }

   /**
   * InitialState is the initial state of the ACME authorization when first fetched from the ACME server. If an Authorization is already &#39;valid&#39;, the Order controller will not create a Challenge resource for the authorization. This will occur when working with an ACME server that enables &#39;authz reuse&#39; (such as Let&#39;s Encrypt&#39;s production endpoint). If not set and &#39;identifier&#39; is set, the state is assumed to be pending and a Challenge will be created.
   * @return initialState
  **/
  @jakarta.annotation.Nullable
  public InitialStateEnum getInitialState() {
    return initialState;
  }


  public void setInitialState(InitialStateEnum initialState) {
    this.initialState = initialState;
  }


  public V1OrderStatusAuthorizationsInner url(String url) {
    
    this.url = url;
    return this;
  }

   /**
   * URL is the URL of the Authorization that must be completed
   * @return url
  **/
  @jakarta.annotation.Nonnull
  public String getUrl() {
    return url;
  }


  public void setUrl(String url) {
    this.url = url;
  }


  public V1OrderStatusAuthorizationsInner wildcard(Boolean wildcard) {
    
    this.wildcard = wildcard;
    return this;
  }

   /**
   * Wildcard will be true if this authorization is for a wildcard DNS name. If this is true, the identifier will be the *non-wildcard* version of the DNS name. For example, if &#39;*.example.com&#39; is the DNS name being validated, this field will be &#39;true&#39; and the &#39;identifier&#39; field will be &#39;example.com&#39;.
   * @return wildcard
  **/
  @jakarta.annotation.Nullable
  public Boolean getWildcard() {
    return wildcard;
  }


  public void setWildcard(Boolean wildcard) {
    this.wildcard = wildcard;
  }



  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    V1OrderStatusAuthorizationsInner v1OrderStatusAuthorizationsInner = (V1OrderStatusAuthorizationsInner) o;
    return Objects.equals(this.challenges, v1OrderStatusAuthorizationsInner.challenges) &&
        Objects.equals(this.identifier, v1OrderStatusAuthorizationsInner.identifier) &&
        Objects.equals(this.initialState, v1OrderStatusAuthorizationsInner.initialState) &&
        Objects.equals(this.url, v1OrderStatusAuthorizationsInner.url) &&
        Objects.equals(this.wildcard, v1OrderStatusAuthorizationsInner.wildcard);
  }

  @Override
  public int hashCode() {
    return Objects.hash(challenges, identifier, initialState, url, wildcard);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class V1OrderStatusAuthorizationsInner {\n");
    sb.append("    challenges: ").append(toIndentedString(challenges)).append("\n");
    sb.append("    identifier: ").append(toIndentedString(identifier)).append("\n");
    sb.append("    initialState: ").append(toIndentedString(initialState)).append("\n");
    sb.append("    url: ").append(toIndentedString(url)).append("\n");
    sb.append("    wildcard: ").append(toIndentedString(wildcard)).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("challenges");
    openapiFields.add("identifier");
    openapiFields.add("initialState");
    openapiFields.add("url");
    openapiFields.add("wildcard");

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

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

      // check to make sure all required properties/fields are present in the JSON string
      for (String requiredField : V1OrderStatusAuthorizationsInner.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("challenges") != null && !jsonObj.get("challenges").isJsonNull()) {
        JsonArray jsonArraychallenges = jsonObj.getAsJsonArray("challenges");
        if (jsonArraychallenges != null) {
          // ensure the json data is an array
          if (!jsonObj.get("challenges").isJsonArray()) {
            throw new IllegalArgumentException(String.format("Expected the field `challenges` to be an array in the JSON string but got `%s`", jsonObj.get("challenges").toString()));
          }

          // validate the optional field `challenges` (array)
          for (int i = 0; i < jsonArraychallenges.size(); i++) {
            V1OrderStatusAuthorizationsInnerChallengesInner.validateJsonObject(jsonArraychallenges.get(i).getAsJsonObject());
          };
        }
      }
      if ((jsonObj.get("identifier") != null && !jsonObj.get("identifier").isJsonNull()) && !jsonObj.get("identifier").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `identifier` to be a primitive type in the JSON string but got `%s`", jsonObj.get("identifier").toString()));
      }
      if ((jsonObj.get("initialState") != null && !jsonObj.get("initialState").isJsonNull()) && !jsonObj.get("initialState").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `initialState` to be a primitive type in the JSON string but got `%s`", jsonObj.get("initialState").toString()));
      }
      if (!jsonObj.get("url").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `url` to be a primitive type in the JSON string but got `%s`", jsonObj.get("url").toString()));
      }
  }

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

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

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

       }.nullSafe();
    }
  }

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

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

