/*
 * Tribufu API
 * API to access Tribufu services.
 *
 * The version of the OpenAPI document: 1.3.0
 * Contact: contact@tribufu.com
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */


package com.tribufu.generated.models;

import java.util.Objects;
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 com.tribufu.generated.models.GameServerStatus;
import java.io.IOException;
import java.time.OffsetDateTime;
import java.util.Arrays;
import org.openapitools.jackson.nullable.JsonNullable;

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 com.tribufu.generated.JSON;

/**
 * GameServerQuery
 */
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2025-12-27T09:52:38.593392400-03:00[America/Sao_Paulo]", comments = "Generator version: 7.12.0")
public class GameServerQuery {
  public static final String SERIALIZED_NAME_ID = "id";
  @SerializedName(SERIALIZED_NAME_ID)
  @javax.annotation.Nullable
  private String id;

  public static final String SERIALIZED_NAME_SERVER_ID = "server_id";
  @SerializedName(SERIALIZED_NAME_SERVER_ID)
  @javax.annotation.Nullable
  private String serverId;

  public static final String SERIALIZED_NAME_STATUS = "status";
  @SerializedName(SERIALIZED_NAME_STATUS)
  @javax.annotation.Nullable
  private GameServerStatus status;

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

  public static final String SERIALIZED_NAME_CURRENT_PLAYERS = "current_players";
  @SerializedName(SERIALIZED_NAME_CURRENT_PLAYERS)
  @javax.annotation.Nullable
  private Integer currentPlayers;

  public static final String SERIALIZED_NAME_MAX_PLAYERS = "max_players";
  @SerializedName(SERIALIZED_NAME_MAX_PLAYERS)
  @javax.annotation.Nullable
  private Integer maxPlayers;

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

  public static final String SERIALIZED_NAME_CREATED = "created";
  @SerializedName(SERIALIZED_NAME_CREATED)
  @javax.annotation.Nullable
  private OffsetDateTime created;

  public GameServerQuery() {
  }

  public GameServerQuery id(@javax.annotation.Nullable String id) {
    this.id = id;
    return this;
  }

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

  public void setId(@javax.annotation.Nullable String id) {
    this.id = id;
  }


  public GameServerQuery serverId(@javax.annotation.Nullable String serverId) {
    this.serverId = serverId;
    return this;
  }

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

  public void setServerId(@javax.annotation.Nullable String serverId) {
    this.serverId = serverId;
  }


  public GameServerQuery status(@javax.annotation.Nullable GameServerStatus status) {
    this.status = status;
    return this;
  }

  /**
   * Get status
   * @return status
   */
  @javax.annotation.Nullable
  public GameServerStatus getStatus() {
    return status;
  }

  public void setStatus(@javax.annotation.Nullable GameServerStatus status) {
    this.status = status;
  }


  public GameServerQuery ping(@javax.annotation.Nullable Integer ping) {
    this.ping = ping;
    return this;
  }

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

  public void setPing(@javax.annotation.Nullable Integer ping) {
    this.ping = ping;
  }


  public GameServerQuery currentPlayers(@javax.annotation.Nullable Integer currentPlayers) {
    this.currentPlayers = currentPlayers;
    return this;
  }

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

  public void setCurrentPlayers(@javax.annotation.Nullable Integer currentPlayers) {
    this.currentPlayers = currentPlayers;
  }


  public GameServerQuery maxPlayers(@javax.annotation.Nullable Integer maxPlayers) {
    this.maxPlayers = maxPlayers;
    return this;
  }

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

  public void setMaxPlayers(@javax.annotation.Nullable Integer maxPlayers) {
    this.maxPlayers = maxPlayers;
  }


  public GameServerQuery motd(@javax.annotation.Nullable String motd) {
    this.motd = motd;
    return this;
  }

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

  public void setMotd(@javax.annotation.Nullable String motd) {
    this.motd = motd;
  }


  public GameServerQuery created(@javax.annotation.Nullable OffsetDateTime created) {
    this.created = created;
    return this;
  }

  /**
   * Get created
   * @return created
   */
  @javax.annotation.Nullable
  public OffsetDateTime getCreated() {
    return created;
  }

  public void setCreated(@javax.annotation.Nullable OffsetDateTime created) {
    this.created = created;
  }



  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    GameServerQuery gameServerQuery = (GameServerQuery) o;
    return Objects.equals(this.id, gameServerQuery.id) &&
        Objects.equals(this.serverId, gameServerQuery.serverId) &&
        Objects.equals(this.status, gameServerQuery.status) &&
        Objects.equals(this.ping, gameServerQuery.ping) &&
        Objects.equals(this.currentPlayers, gameServerQuery.currentPlayers) &&
        Objects.equals(this.maxPlayers, gameServerQuery.maxPlayers) &&
        Objects.equals(this.motd, gameServerQuery.motd) &&
        Objects.equals(this.created, gameServerQuery.created);
  }

  private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
    return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && Objects.deepEquals(a.get(), b.get()));
  }

  @Override
  public int hashCode() {
    return Objects.hash(id, serverId, status, ping, currentPlayers, maxPlayers, motd, created);
  }

  private static <T> int hashCodeNullable(JsonNullable<T> a) {
    if (a == null) {
      return 1;
    }
    return a.isPresent() ? Arrays.deepHashCode(new Object[]{a.get()}) : 31;
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class GameServerQuery {\n");
    sb.append("    id: ").append(toIndentedString(id)).append("\n");
    sb.append("    serverId: ").append(toIndentedString(serverId)).append("\n");
    sb.append("    status: ").append(toIndentedString(status)).append("\n");
    sb.append("    ping: ").append(toIndentedString(ping)).append("\n");
    sb.append("    currentPlayers: ").append(toIndentedString(currentPlayers)).append("\n");
    sb.append("    maxPlayers: ").append(toIndentedString(maxPlayers)).append("\n");
    sb.append("    motd: ").append(toIndentedString(motd)).append("\n");
    sb.append("    created: ").append(toIndentedString(created)).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("id");
    openapiFields.add("server_id");
    openapiFields.add("status");
    openapiFields.add("ping");
    openapiFields.add("current_players");
    openapiFields.add("max_players");
    openapiFields.add("motd");
    openapiFields.add("created");

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

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

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

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

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

       }.nullSafe();
    }
  }

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

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

