/*
 * 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.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.openapitools.client.model.PosEntryModel;

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;

/**
 * BlockTemplateRequestModel
 */
@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 BlockTemplateRequestModel {
  public static final String SERIALIZED_NAME_MINER_ADDRESS = "miner_address";
  @SerializedName(SERIALIZED_NAME_MINER_ADDRESS)
  @javax.annotation.Nullable
  private String minerAddress;

  public static final String SERIALIZED_NAME_STAKEHOLDER_ADDRESS = "stakeholder_address";
  @SerializedName(SERIALIZED_NAME_STAKEHOLDER_ADDRESS)
  @javax.annotation.Nullable
  private String stakeholderAddress;

  public static final String SERIALIZED_NAME_EX_NONCE = "ex_nonce";
  @SerializedName(SERIALIZED_NAME_EX_NONCE)
  @javax.annotation.Nullable
  private String exNonce;

  public static final String SERIALIZED_NAME_POS_BLOCK = "pos_block";
  @SerializedName(SERIALIZED_NAME_POS_BLOCK)
  @javax.annotation.Nullable
  private Boolean posBlock;

  public static final String SERIALIZED_NAME_IGNORE_POW_TS_CHECK = "ignore_pow_ts_check";
  @SerializedName(SERIALIZED_NAME_IGNORE_POW_TS_CHECK)
  @javax.annotation.Nullable
  private Boolean ignorePowTsCheck;

  public static final String SERIALIZED_NAME_PE = "pe";
  @SerializedName(SERIALIZED_NAME_PE)
  @javax.annotation.Nullable
  private PosEntryModel pe;

  public static final String SERIALIZED_NAME_EXPLICIT_TXS = "explicit_txs";
  @SerializedName(SERIALIZED_NAME_EXPLICIT_TXS)
  @javax.annotation.Nullable
  private List<String> explicitTxs = new ArrayList<>();

  public BlockTemplateRequestModel() {
  }

  public BlockTemplateRequestModel minerAddress(@javax.annotation.Nullable String minerAddress) {
    this.minerAddress = minerAddress;
    return this;
  }

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

  public void setMinerAddress(@javax.annotation.Nullable String minerAddress) {
    this.minerAddress = minerAddress;
  }


  public BlockTemplateRequestModel stakeholderAddress(@javax.annotation.Nullable String stakeholderAddress) {
    this.stakeholderAddress = stakeholderAddress;
    return this;
  }

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

  public void setStakeholderAddress(@javax.annotation.Nullable String stakeholderAddress) {
    this.stakeholderAddress = stakeholderAddress;
  }


  public BlockTemplateRequestModel exNonce(@javax.annotation.Nullable String exNonce) {
    this.exNonce = exNonce;
    return this;
  }

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

  public void setExNonce(@javax.annotation.Nullable String exNonce) {
    this.exNonce = exNonce;
  }


  public BlockTemplateRequestModel posBlock(@javax.annotation.Nullable Boolean posBlock) {
    this.posBlock = posBlock;
    return this;
  }

  /**
   * Get posBlock
   * @return posBlock
   */
  @javax.annotation.Nullable
  public Boolean getPosBlock() {
    return posBlock;
  }

  public void setPosBlock(@javax.annotation.Nullable Boolean posBlock) {
    this.posBlock = posBlock;
  }


  public BlockTemplateRequestModel ignorePowTsCheck(@javax.annotation.Nullable Boolean ignorePowTsCheck) {
    this.ignorePowTsCheck = ignorePowTsCheck;
    return this;
  }

  /**
   * Get ignorePowTsCheck
   * @return ignorePowTsCheck
   */
  @javax.annotation.Nullable
  public Boolean getIgnorePowTsCheck() {
    return ignorePowTsCheck;
  }

  public void setIgnorePowTsCheck(@javax.annotation.Nullable Boolean ignorePowTsCheck) {
    this.ignorePowTsCheck = ignorePowTsCheck;
  }


  public BlockTemplateRequestModel pe(@javax.annotation.Nullable PosEntryModel pe) {
    this.pe = pe;
    return this;
  }

  /**
   * Get pe
   * @return pe
   */
  @javax.annotation.Nullable
  public PosEntryModel getPe() {
    return pe;
  }

  public void setPe(@javax.annotation.Nullable PosEntryModel pe) {
    this.pe = pe;
  }


  public BlockTemplateRequestModel explicitTxs(@javax.annotation.Nullable List<String> explicitTxs) {
    this.explicitTxs = explicitTxs;
    return this;
  }

  public BlockTemplateRequestModel addExplicitTxsItem(String explicitTxsItem) {
    if (this.explicitTxs == null) {
      this.explicitTxs = new ArrayList<>();
    }
    this.explicitTxs.add(explicitTxsItem);
    return this;
  }

  /**
   * Get explicitTxs
   * @return explicitTxs
   */
  @javax.annotation.Nullable
  public List<String> getExplicitTxs() {
    return explicitTxs;
  }

  public void setExplicitTxs(@javax.annotation.Nullable List<String> explicitTxs) {
    this.explicitTxs = explicitTxs;
  }



  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    BlockTemplateRequestModel blockTemplateRequestModel = (BlockTemplateRequestModel) o;
    return Objects.equals(this.minerAddress, blockTemplateRequestModel.minerAddress) &&
        Objects.equals(this.stakeholderAddress, blockTemplateRequestModel.stakeholderAddress) &&
        Objects.equals(this.exNonce, blockTemplateRequestModel.exNonce) &&
        Objects.equals(this.posBlock, blockTemplateRequestModel.posBlock) &&
        Objects.equals(this.ignorePowTsCheck, blockTemplateRequestModel.ignorePowTsCheck) &&
        Objects.equals(this.pe, blockTemplateRequestModel.pe) &&
        Objects.equals(this.explicitTxs, blockTemplateRequestModel.explicitTxs);
  }

  @Override
  public int hashCode() {
    return Objects.hash(minerAddress, stakeholderAddress, exNonce, posBlock, ignorePowTsCheck, pe, explicitTxs);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class BlockTemplateRequestModel {\n");
    sb.append("    minerAddress: ").append(toIndentedString(minerAddress)).append("\n");
    sb.append("    stakeholderAddress: ").append(toIndentedString(stakeholderAddress)).append("\n");
    sb.append("    exNonce: ").append(toIndentedString(exNonce)).append("\n");
    sb.append("    posBlock: ").append(toIndentedString(posBlock)).append("\n");
    sb.append("    ignorePowTsCheck: ").append(toIndentedString(ignorePowTsCheck)).append("\n");
    sb.append("    pe: ").append(toIndentedString(pe)).append("\n");
    sb.append("    explicitTxs: ").append(toIndentedString(explicitTxs)).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("miner_address", "stakeholder_address", "ex_nonce", "pos_block", "ignore_pow_ts_check", "pe", "explicit_txs"));

    // 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 BlockTemplateRequestModel
   */
  public static void validateJsonElement(JsonElement jsonElement) throws IOException {
      if (jsonElement == null) {
        if (!BlockTemplateRequestModel.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null
          throw new IllegalArgumentException(String.format(Locale.ROOT, "The required field(s) %s in BlockTemplateRequestModel is not found in the empty JSON string", BlockTemplateRequestModel.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 (!BlockTemplateRequestModel.openapiFields.contains(entry.getKey())) {
          throw new IllegalArgumentException(String.format(Locale.ROOT, "The field `%s` in the JSON string is not defined in the `BlockTemplateRequestModel` properties. JSON: %s", entry.getKey(), jsonElement.toString()));
        }
      }
        JsonObject jsonObj = jsonElement.getAsJsonObject();
      if ((jsonObj.get("miner_address") != null && !jsonObj.get("miner_address").isJsonNull()) && !jsonObj.get("miner_address").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format(Locale.ROOT, "Expected the field `miner_address` to be a primitive type in the JSON string but got `%s`", jsonObj.get("miner_address").toString()));
      }
      if ((jsonObj.get("stakeholder_address") != null && !jsonObj.get("stakeholder_address").isJsonNull()) && !jsonObj.get("stakeholder_address").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format(Locale.ROOT, "Expected the field `stakeholder_address` to be a primitive type in the JSON string but got `%s`", jsonObj.get("stakeholder_address").toString()));
      }
      if ((jsonObj.get("ex_nonce") != null && !jsonObj.get("ex_nonce").isJsonNull()) && !jsonObj.get("ex_nonce").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format(Locale.ROOT, "Expected the field `ex_nonce` to be a primitive type in the JSON string but got `%s`", jsonObj.get("ex_nonce").toString()));
      }
      // validate the optional field `pe`
      if (jsonObj.get("pe") != null && !jsonObj.get("pe").isJsonNull()) {
        PosEntryModel.validateJsonElement(jsonObj.get("pe"));
      }
      // ensure the optional json data is an array if present
      if (jsonObj.get("explicit_txs") != null && !jsonObj.get("explicit_txs").isJsonNull() && !jsonObj.get("explicit_txs").isJsonArray()) {
        throw new IllegalArgumentException(String.format(Locale.ROOT, "Expected the field `explicit_txs` to be an array in the JSON string but got `%s`", jsonObj.get("explicit_txs").toString()));
      }
  }

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

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

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

       }.nullSafe();
    }
  }

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

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

