/*
 * load simulation - OpenAPI 3.0
 * describe list of requests
 *
 * The version of the OpenAPI document: 1.0.0
 *
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

package net.consensys.zkevm.load.swagger;

import com.google.gson.JsonElement;
import com.google.gson.annotations.SerializedName;
import java.io.IOException;
import java.util.HashSet;
import java.util.Objects;
import net.consensys.zkevm.load.model.JSON;

/** Contract */
public class Contract {
  public static final String SERIALIZED_NAME_CONTRACT_CALL_TYPE = "contractCallType";

  @SerializedName(SERIALIZED_NAME_CONTRACT_CALL_TYPE)
  protected String contractCallType;

  public Contract() {
    this.contractCallType = this.getClass().getSimpleName();
  }

  public Contract contractCallType(String contractCallType) {
    this.contractCallType = contractCallType;
    return this;
  }

  /**
   * Get contractCallType
   *
   * @return contractCallType
   */
  @javax.annotation.Nonnull
  public String getContractCallType() {
    return contractCallType;
  }

  public void setContractCallType(String contractCallType) {
    this.contractCallType = contractCallType;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    Contract contract = (Contract) o;
    return Objects.equals(this.contractCallType, contract.contractCallType);
  }

  @Override
  public int hashCode() {
    return Objects.hash(contractCallType);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class Contract {\n");
    sb.append("    contractCallType: ").append(toIndentedString(contractCallType)).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("contractCallType");

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

  /**
   * 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 Contract
   */
  public static void validateJsonElement(JsonElement jsonElement) throws IOException {
    if (jsonElement == null) {
      if (!Contract.openapiRequiredFields
          .isEmpty()) { // has required fields but JSON element is null
        throw new IllegalArgumentException(
            String.format(
                "The required field(s) %s in Contract is not found in the empty JSON string",
                Contract.openapiRequiredFields.toString()));
      }
    }

    String discriminatorValue = jsonElement.getAsJsonObject().get("contractCallType").getAsString();
    switch (discriminatorValue) {
      case "CallContractReference":
        CallContractReference.validateJsonElement(jsonElement);
        break;
      case "CallExistingContract":
        CallExistingContract.validateJsonElement(jsonElement);
        break;
      case "CreateContract":
        CreateContract.validateJsonElement(jsonElement);
        break;
      default:
        throw new IllegalArgumentException(
            String.format(
                "The value of the `contractCallType` field `%s` does not match any key defined in the discriminator's mapping.",
                discriminatorValue));
    }
  }

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

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