/*
 * Lethean Blockchain API
 * OpenAPI for Lethean Blockchain
 *
 * The version of the OpenAPI document: 6.0.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 org.openapitools.client.model;

import java.util.Objects;
import java.util.Locale;
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 java.io.IOException;
import java.util.Arrays;
import org.openapitools.client.model.BlockProcessingPerformanceModel;
import org.openapitools.client.model.DbStatInfoModel;
import org.openapitools.client.model.TxPoolPerformanceModel;
import org.openapitools.client.model.TxProcessingPerformanceModel;

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.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Locale;

import invalidPackageName.JSON;

/**
 * PerformanceModel
 */
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2025-10-19T15:35:02.750468+01:00[Europe/London]", comments = "Generator version: 7.16.0")
public class PerformanceModel {
  public static final String SERIALIZED_NAME_BLOCK_PROCESSING = "block_processing";
  @SerializedName(SERIALIZED_NAME_BLOCK_PROCESSING)
  @javax.annotation.Nullable
  private BlockProcessingPerformanceModel blockProcessing;

  public static final String SERIALIZED_NAME_TX_PROCESSING = "tx_processing";
  @SerializedName(SERIALIZED_NAME_TX_PROCESSING)
  @javax.annotation.Nullable
  private TxProcessingPerformanceModel txProcessing;

  public static final String SERIALIZED_NAME_TX_POOL = "tx_pool";
  @SerializedName(SERIALIZED_NAME_TX_POOL)
  @javax.annotation.Nullable
  private TxPoolPerformanceModel txPool;

  public static final String SERIALIZED_NAME_DB_STAT_INFO = "db_stat_info";
  @SerializedName(SERIALIZED_NAME_DB_STAT_INFO)
  @javax.annotation.Nullable
  private DbStatInfoModel dbStatInfo;

  public PerformanceModel() {
  }

  public PerformanceModel blockProcessing(@javax.annotation.Nullable BlockProcessingPerformanceModel blockProcessing) {
    this.blockProcessing = blockProcessing;
    return this;
  }

  /**
   * Get blockProcessing
   * @return blockProcessing
   */
  @javax.annotation.Nullable
  public BlockProcessingPerformanceModel getBlockProcessing() {
    return blockProcessing;
  }

  public void setBlockProcessing(@javax.annotation.Nullable BlockProcessingPerformanceModel blockProcessing) {
    this.blockProcessing = blockProcessing;
  }


  public PerformanceModel txProcessing(@javax.annotation.Nullable TxProcessingPerformanceModel txProcessing) {
    this.txProcessing = txProcessing;
    return this;
  }

  /**
   * Get txProcessing
   * @return txProcessing
   */
  @javax.annotation.Nullable
  public TxProcessingPerformanceModel getTxProcessing() {
    return txProcessing;
  }

  public void setTxProcessing(@javax.annotation.Nullable TxProcessingPerformanceModel txProcessing) {
    this.txProcessing = txProcessing;
  }


  public PerformanceModel txPool(@javax.annotation.Nullable TxPoolPerformanceModel txPool) {
    this.txPool = txPool;
    return this;
  }

  /**
   * Get txPool
   * @return txPool
   */
  @javax.annotation.Nullable
  public TxPoolPerformanceModel getTxPool() {
    return txPool;
  }

  public void setTxPool(@javax.annotation.Nullable TxPoolPerformanceModel txPool) {
    this.txPool = txPool;
  }


  public PerformanceModel dbStatInfo(@javax.annotation.Nullable DbStatInfoModel dbStatInfo) {
    this.dbStatInfo = dbStatInfo;
    return this;
  }

  /**
   * Get dbStatInfo
   * @return dbStatInfo
   */
  @javax.annotation.Nullable
  public DbStatInfoModel getDbStatInfo() {
    return dbStatInfo;
  }

  public void setDbStatInfo(@javax.annotation.Nullable DbStatInfoModel dbStatInfo) {
    this.dbStatInfo = dbStatInfo;
  }



  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    PerformanceModel performanceModel = (PerformanceModel) o;
    return Objects.equals(this.blockProcessing, performanceModel.blockProcessing) &&
        Objects.equals(this.txProcessing, performanceModel.txProcessing) &&
        Objects.equals(this.txPool, performanceModel.txPool) &&
        Objects.equals(this.dbStatInfo, performanceModel.dbStatInfo);
  }

  @Override
  public int hashCode() {
    return Objects.hash(blockProcessing, txProcessing, txPool, dbStatInfo);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class PerformanceModel {\n");
    sb.append("    blockProcessing: ").append(toIndentedString(blockProcessing)).append("\n");
    sb.append("    txProcessing: ").append(toIndentedString(txProcessing)).append("\n");
    sb.append("    txPool: ").append(toIndentedString(txPool)).append("\n");
    sb.append("    dbStatInfo: ").append(toIndentedString(dbStatInfo)).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>(Arrays.asList("block_processing", "tx_processing", "tx_pool", "db_stat_info"));

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

  /**
   * Validates the JSON Element and throws an exception if issues found
   *
   * @param jsonElement JSON Element
   * @throws IOException if the JSON Element is invalid with respect to PerformanceModel
   */
  public static void validateJsonElement(JsonElement jsonElement) throws IOException {
      if (jsonElement == null) {
        if (!PerformanceModel.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null
          throw new IllegalArgumentException(String.format(Locale.ROOT, "The required field(s) %s in PerformanceModel is not found in the empty JSON string", PerformanceModel.openapiRequiredFields.toString()));
        }
      }

      Set<Map.Entry<String, JsonElement>> entries = jsonElement.getAsJsonObject().entrySet();
      // check to see if the JSON string contains additional fields
      for (Map.Entry<String, JsonElement> entry : entries) {
        if (!PerformanceModel.openapiFields.contains(entry.getKey())) {
          throw new IllegalArgumentException(String.format(Locale.ROOT, "The field `%s` in the JSON string is not defined in the `PerformanceModel` properties. JSON: %s", entry.getKey(), jsonElement.toString()));
        }
      }
        JsonObject jsonObj = jsonElement.getAsJsonObject();
      // validate the optional field `block_processing`
      if (jsonObj.get("block_processing") != null && !jsonObj.get("block_processing").isJsonNull()) {
        BlockProcessingPerformanceModel.validateJsonElement(jsonObj.get("block_processing"));
      }
      // validate the optional field `tx_processing`
      if (jsonObj.get("tx_processing") != null && !jsonObj.get("tx_processing").isJsonNull()) {
        TxProcessingPerformanceModel.validateJsonElement(jsonObj.get("tx_processing"));
      }
      // validate the optional field `tx_pool`
      if (jsonObj.get("tx_pool") != null && !jsonObj.get("tx_pool").isJsonNull()) {
        TxPoolPerformanceModel.validateJsonElement(jsonObj.get("tx_pool"));
      }
      // validate the optional field `db_stat_info`
      if (jsonObj.get("db_stat_info") != null && !jsonObj.get("db_stat_info").isJsonNull()) {
        DbStatInfoModel.validateJsonElement(jsonObj.get("db_stat_info"));
      }
  }

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

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

           @Override
           public PerformanceModel read(JsonReader in) throws IOException {
             JsonElement jsonElement = elementAdapter.read(in);
             validateJsonElement(jsonElement);
             return thisAdapter.fromJsonTree(jsonElement);
           }

       }.nullSafe();
    }
  }

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

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

