/*
 * 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.TxGenerationContextModel;

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;

/**
 * BlockTemplateModel
 */
@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 BlockTemplateModel {
  public static final String SERIALIZED_NAME_BLOCKTEMPLATE_BLOB = "blocktemplate_blob";
  @SerializedName(SERIALIZED_NAME_BLOCKTEMPLATE_BLOB)
  @javax.annotation.Nullable
  private String blocktemplateBlob;

  public static final String SERIALIZED_NAME_DIFFICULTY = "difficulty";
  @SerializedName(SERIALIZED_NAME_DIFFICULTY)
  @javax.annotation.Nullable
  private String difficulty;

  public static final String SERIALIZED_NAME_HEIGHT = "height";
  @SerializedName(SERIALIZED_NAME_HEIGHT)
  @javax.annotation.Nullable
  private Integer height;

  public static final String SERIALIZED_NAME_MINER_TX_TGC = "miner_tx_tgc";
  @SerializedName(SERIALIZED_NAME_MINER_TX_TGC)
  @javax.annotation.Nullable
  private TxGenerationContextModel minerTxTgc;

  public static final String SERIALIZED_NAME_BLOCK_REWARD_WITHOUT_FEE = "block_reward_without_fee";
  @SerializedName(SERIALIZED_NAME_BLOCK_REWARD_WITHOUT_FEE)
  @javax.annotation.Nullable
  private Integer blockRewardWithoutFee;

  public static final String SERIALIZED_NAME_BLOCK_REWARD = "block_reward";
  @SerializedName(SERIALIZED_NAME_BLOCK_REWARD)
  @javax.annotation.Nullable
  private Integer blockReward;

  public static final String SERIALIZED_NAME_TXS_FEE = "txs_fee";
  @SerializedName(SERIALIZED_NAME_TXS_FEE)
  @javax.annotation.Nullable
  private Integer txsFee;

  public static final String SERIALIZED_NAME_PREV_HASH = "prev_hash";
  @SerializedName(SERIALIZED_NAME_PREV_HASH)
  @javax.annotation.Nullable
  private String prevHash;

  public static final String SERIALIZED_NAME_SEED = "seed";
  @SerializedName(SERIALIZED_NAME_SEED)
  @javax.annotation.Nullable
  private String seed;

  public BlockTemplateModel() {
  }

  public BlockTemplateModel blocktemplateBlob(@javax.annotation.Nullable String blocktemplateBlob) {
    this.blocktemplateBlob = blocktemplateBlob;
    return this;
  }

  /**
   * Get blocktemplateBlob
   * @return blocktemplateBlob
   */
  @javax.annotation.Nullable
  public String getBlocktemplateBlob() {
    return blocktemplateBlob;
  }

  public void setBlocktemplateBlob(@javax.annotation.Nullable String blocktemplateBlob) {
    this.blocktemplateBlob = blocktemplateBlob;
  }


  public BlockTemplateModel difficulty(@javax.annotation.Nullable String difficulty) {
    this.difficulty = difficulty;
    return this;
  }

  /**
   * Get difficulty
   * @return difficulty
   */
  @javax.annotation.Nullable
  public String getDifficulty() {
    return difficulty;
  }

  public void setDifficulty(@javax.annotation.Nullable String difficulty) {
    this.difficulty = difficulty;
  }


  public BlockTemplateModel height(@javax.annotation.Nullable Integer height) {
    this.height = height;
    return this;
  }

  /**
   * Get height
   * @return height
   */
  @javax.annotation.Nullable
  public Integer getHeight() {
    return height;
  }

  public void setHeight(@javax.annotation.Nullable Integer height) {
    this.height = height;
  }


  public BlockTemplateModel minerTxTgc(@javax.annotation.Nullable TxGenerationContextModel minerTxTgc) {
    this.minerTxTgc = minerTxTgc;
    return this;
  }

  /**
   * Get minerTxTgc
   * @return minerTxTgc
   */
  @javax.annotation.Nullable
  public TxGenerationContextModel getMinerTxTgc() {
    return minerTxTgc;
  }

  public void setMinerTxTgc(@javax.annotation.Nullable TxGenerationContextModel minerTxTgc) {
    this.minerTxTgc = minerTxTgc;
  }


  public BlockTemplateModel blockRewardWithoutFee(@javax.annotation.Nullable Integer blockRewardWithoutFee) {
    this.blockRewardWithoutFee = blockRewardWithoutFee;
    return this;
  }

  /**
   * Get blockRewardWithoutFee
   * @return blockRewardWithoutFee
   */
  @javax.annotation.Nullable
  public Integer getBlockRewardWithoutFee() {
    return blockRewardWithoutFee;
  }

  public void setBlockRewardWithoutFee(@javax.annotation.Nullable Integer blockRewardWithoutFee) {
    this.blockRewardWithoutFee = blockRewardWithoutFee;
  }


  public BlockTemplateModel blockReward(@javax.annotation.Nullable Integer blockReward) {
    this.blockReward = blockReward;
    return this;
  }

  /**
   * Get blockReward
   * @return blockReward
   */
  @javax.annotation.Nullable
  public Integer getBlockReward() {
    return blockReward;
  }

  public void setBlockReward(@javax.annotation.Nullable Integer blockReward) {
    this.blockReward = blockReward;
  }


  public BlockTemplateModel txsFee(@javax.annotation.Nullable Integer txsFee) {
    this.txsFee = txsFee;
    return this;
  }

  /**
   * Get txsFee
   * @return txsFee
   */
  @javax.annotation.Nullable
  public Integer getTxsFee() {
    return txsFee;
  }

  public void setTxsFee(@javax.annotation.Nullable Integer txsFee) {
    this.txsFee = txsFee;
  }


  public BlockTemplateModel prevHash(@javax.annotation.Nullable String prevHash) {
    this.prevHash = prevHash;
    return this;
  }

  /**
   * Get prevHash
   * @return prevHash
   */
  @javax.annotation.Nullable
  public String getPrevHash() {
    return prevHash;
  }

  public void setPrevHash(@javax.annotation.Nullable String prevHash) {
    this.prevHash = prevHash;
  }


  public BlockTemplateModel seed(@javax.annotation.Nullable String seed) {
    this.seed = seed;
    return this;
  }

  /**
   * Get seed
   * @return seed
   */
  @javax.annotation.Nullable
  public String getSeed() {
    return seed;
  }

  public void setSeed(@javax.annotation.Nullable String seed) {
    this.seed = seed;
  }



  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    BlockTemplateModel blockTemplateModel = (BlockTemplateModel) o;
    return Objects.equals(this.blocktemplateBlob, blockTemplateModel.blocktemplateBlob) &&
        Objects.equals(this.difficulty, blockTemplateModel.difficulty) &&
        Objects.equals(this.height, blockTemplateModel.height) &&
        Objects.equals(this.minerTxTgc, blockTemplateModel.minerTxTgc) &&
        Objects.equals(this.blockRewardWithoutFee, blockTemplateModel.blockRewardWithoutFee) &&
        Objects.equals(this.blockReward, blockTemplateModel.blockReward) &&
        Objects.equals(this.txsFee, blockTemplateModel.txsFee) &&
        Objects.equals(this.prevHash, blockTemplateModel.prevHash) &&
        Objects.equals(this.seed, blockTemplateModel.seed);
  }

  @Override
  public int hashCode() {
    return Objects.hash(blocktemplateBlob, difficulty, height, minerTxTgc, blockRewardWithoutFee, blockReward, txsFee, prevHash, seed);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class BlockTemplateModel {\n");
    sb.append("    blocktemplateBlob: ").append(toIndentedString(blocktemplateBlob)).append("\n");
    sb.append("    difficulty: ").append(toIndentedString(difficulty)).append("\n");
    sb.append("    height: ").append(toIndentedString(height)).append("\n");
    sb.append("    minerTxTgc: ").append(toIndentedString(minerTxTgc)).append("\n");
    sb.append("    blockRewardWithoutFee: ").append(toIndentedString(blockRewardWithoutFee)).append("\n");
    sb.append("    blockReward: ").append(toIndentedString(blockReward)).append("\n");
    sb.append("    txsFee: ").append(toIndentedString(txsFee)).append("\n");
    sb.append("    prevHash: ").append(toIndentedString(prevHash)).append("\n");
    sb.append("    seed: ").append(toIndentedString(seed)).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("blocktemplate_blob", "difficulty", "height", "miner_tx_tgc", "block_reward_without_fee", "block_reward", "txs_fee", "prev_hash", "seed"));

    // 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 BlockTemplateModel
   */
  public static void validateJsonElement(JsonElement jsonElement) throws IOException {
      if (jsonElement == null) {
        if (!BlockTemplateModel.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null
          throw new IllegalArgumentException(String.format(Locale.ROOT, "The required field(s) %s in BlockTemplateModel is not found in the empty JSON string", BlockTemplateModel.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 (!BlockTemplateModel.openapiFields.contains(entry.getKey())) {
          throw new IllegalArgumentException(String.format(Locale.ROOT, "The field `%s` in the JSON string is not defined in the `BlockTemplateModel` properties. JSON: %s", entry.getKey(), jsonElement.toString()));
        }
      }
        JsonObject jsonObj = jsonElement.getAsJsonObject();
      if ((jsonObj.get("blocktemplate_blob") != null && !jsonObj.get("blocktemplate_blob").isJsonNull()) && !jsonObj.get("blocktemplate_blob").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format(Locale.ROOT, "Expected the field `blocktemplate_blob` to be a primitive type in the JSON string but got `%s`", jsonObj.get("blocktemplate_blob").toString()));
      }
      if ((jsonObj.get("difficulty") != null && !jsonObj.get("difficulty").isJsonNull()) && !jsonObj.get("difficulty").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format(Locale.ROOT, "Expected the field `difficulty` to be a primitive type in the JSON string but got `%s`", jsonObj.get("difficulty").toString()));
      }
      // validate the optional field `miner_tx_tgc`
      if (jsonObj.get("miner_tx_tgc") != null && !jsonObj.get("miner_tx_tgc").isJsonNull()) {
        TxGenerationContextModel.validateJsonElement(jsonObj.get("miner_tx_tgc"));
      }
      if ((jsonObj.get("prev_hash") != null && !jsonObj.get("prev_hash").isJsonNull()) && !jsonObj.get("prev_hash").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format(Locale.ROOT, "Expected the field `prev_hash` to be a primitive type in the JSON string but got `%s`", jsonObj.get("prev_hash").toString()));
      }
      if ((jsonObj.get("seed") != null && !jsonObj.get("seed").isJsonNull()) && !jsonObj.get("seed").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format(Locale.ROOT, "Expected the field `seed` to be a primitive type in the JSON string but got `%s`", jsonObj.get("seed").toString()));
      }
  }

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

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

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

       }.nullSafe();
    }
  }

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

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

