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

/** Parameter */
public class Parameter {
  public static final String SERIALIZED_NAME_TYPE = "type";

  @SerializedName(SERIALIZED_NAME_TYPE)
  protected String type;

  public Parameter() {
    this.type = this.getClass().getSimpleName();
  }

  public Parameter type(String type) {
    this.type = type;
    return this;
  }

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

  public void setType(String type) {
    this.type = type;
  }

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

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

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

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

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

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

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

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