/*
 * 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.V1CertificateRequestStatusConditionsInner;
import java.io.IOException;
import java.time.OffsetDateTime;
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;

/**
 * Status of the CertificateRequest. This is set and managed automatically. Read-only. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
 */
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2024-03-01T07:00:20.132973Z[Etc/UTC]")
public class V1CertificateRequestStatus {
  public static final String SERIALIZED_NAME_CA = "ca";
  @SerializedName(SERIALIZED_NAME_CA)
  private byte[] ca;

  public static final String SERIALIZED_NAME_CERTIFICATE = "certificate";
  @SerializedName(SERIALIZED_NAME_CERTIFICATE)
  private byte[] certificate;

  public static final String SERIALIZED_NAME_CONDITIONS = "conditions";
  @SerializedName(SERIALIZED_NAME_CONDITIONS)
  private List<V1CertificateRequestStatusConditionsInner> conditions;

  public static final String SERIALIZED_NAME_FAILURE_TIME = "failureTime";
  @SerializedName(SERIALIZED_NAME_FAILURE_TIME)
  private OffsetDateTime failureTime;

  public V1CertificateRequestStatus() {
  }

  public V1CertificateRequestStatus ca(byte[] ca) {
    
    this.ca = ca;
    return this;
  }

   /**
   * The PEM encoded X.509 certificate of the signer, also known as the CA (Certificate Authority). This is set on a best-effort basis by different issuers. If not set, the CA is assumed to be unknown/not available.
   * @return ca
  **/
  @jakarta.annotation.Nullable
  public byte[] getCa() {
    return ca;
  }


  public void setCa(byte[] ca) {
    this.ca = ca;
  }


  public V1CertificateRequestStatus certificate(byte[] certificate) {
    
    this.certificate = certificate;
    return this;
  }

   /**
   * The PEM encoded X.509 certificate resulting from the certificate signing request. If not set, the CertificateRequest has either not been completed or has failed. More information on failure can be found by checking the &#x60;conditions&#x60; field.
   * @return certificate
  **/
  @jakarta.annotation.Nullable
  public byte[] getCertificate() {
    return certificate;
  }


  public void setCertificate(byte[] certificate) {
    this.certificate = certificate;
  }


  public V1CertificateRequestStatus conditions(List<V1CertificateRequestStatusConditionsInner> conditions) {
    
    this.conditions = conditions;
    return this;
  }

  public V1CertificateRequestStatus addConditionsItem(V1CertificateRequestStatusConditionsInner conditionsItem) {
    if (this.conditions == null) {
      this.conditions = new ArrayList<>();
    }
    this.conditions.add(conditionsItem);
    return this;
  }

   /**
   * List of status conditions to indicate the status of a CertificateRequest. Known condition types are &#x60;Ready&#x60;, &#x60;InvalidRequest&#x60;, &#x60;Approved&#x60; and &#x60;Denied&#x60;.
   * @return conditions
  **/
  @jakarta.annotation.Nullable
  public List<V1CertificateRequestStatusConditionsInner> getConditions() {
    return conditions;
  }


  public void setConditions(List<V1CertificateRequestStatusConditionsInner> conditions) {
    this.conditions = conditions;
  }


  public V1CertificateRequestStatus failureTime(OffsetDateTime failureTime) {
    
    this.failureTime = failureTime;
    return this;
  }

   /**
   * FailureTime stores the time that this CertificateRequest failed. This is used to influence garbage collection and back-off.
   * @return failureTime
  **/
  @jakarta.annotation.Nullable
  public OffsetDateTime getFailureTime() {
    return failureTime;
  }


  public void setFailureTime(OffsetDateTime failureTime) {
    this.failureTime = failureTime;
  }



  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    V1CertificateRequestStatus v1CertificateRequestStatus = (V1CertificateRequestStatus) o;
    return Arrays.equals(this.ca, v1CertificateRequestStatus.ca) &&
        Arrays.equals(this.certificate, v1CertificateRequestStatus.certificate) &&
        Objects.equals(this.conditions, v1CertificateRequestStatus.conditions) &&
        Objects.equals(this.failureTime, v1CertificateRequestStatus.failureTime);
  }

  @Override
  public int hashCode() {
    return Objects.hash(Arrays.hashCode(ca), Arrays.hashCode(certificate), conditions, failureTime);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class V1CertificateRequestStatus {\n");
    sb.append("    ca: ").append(toIndentedString(ca)).append("\n");
    sb.append("    certificate: ").append(toIndentedString(certificate)).append("\n");
    sb.append("    conditions: ").append(toIndentedString(conditions)).append("\n");
    sb.append("    failureTime: ").append(toIndentedString(failureTime)).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("ca");
    openapiFields.add("certificate");
    openapiFields.add("conditions");
    openapiFields.add("failureTime");

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

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

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

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

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

       }.nullSafe();
    }
  }

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

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

