# NOTE: This file is auto generated by OpenAPI Generator 7.7.0 (https://openapi-generator.tech).
# Do not edit this file manually.

defmodule GeoproxServer.Api.GeoshardApi do
  @moduledoc """
  API calls for all endpoints tagged `GeoshardApi`.
  """

  alias GeoproxServer.Connection
  import GeoproxServer.RequestBuilder

  @doc """
  Create geospatial index
  Creates an in-memory index within this geoshard

  ### Parameters

  - `connection` (GeoproxServer.Connection): Connection to server
  - `index` (String.t): Geospatial index name
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, GeoproxServer.Model.CreateIndexResponse.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec create_index(Tesla.Env.client, String.t, keyword()) :: {:ok, GeoproxServer.Model.CreateIndexResponse.t} | {:error, Tesla.Env.t}
  def create_index(connection, index, _opts \\ []) do
    request =
      %{}
      |> method(:post)
      |> url("/api/v1/shard/#{index}")
      |> ensure_body()
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {201, GeoproxServer.Model.CreateIndexResponse}
    ])
  end

  @doc """
  Deletes geospatial index
  Drop index. All keys will be lost

  ### Parameters

  - `connection` (GeoproxServer.Connection): Connection to server
  - `index` (String.t): Geospatial index name
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, GeoproxServer.Model.DropIndexResponse.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec drop_index(Tesla.Env.client, String.t, keyword()) :: {:ok, GeoproxServer.Model.DropIndexResponse.t} | {:error, Tesla.Env.t}
  def drop_index(connection, index, _opts \\ []) do
    request =
      %{}
      |> method(:delete)
      |> url("/api/v1/shard/#{index}")
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {202, GeoproxServer.Model.DropIndexResponse}
    ])
  end

  @doc """
  Insert key into index
  Inserts key into geospatial index

  ### Parameters

  - `connection` (GeoproxServer.Connection): Connection to server
  - `index` (String.t): Geospatial index name
  - `insert_key` (InsertKey): 
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, GeoproxServer.Model.InsertKeyResponse.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec insert_key(Tesla.Env.client, String.t, GeoproxServer.Model.InsertKey.t, keyword()) :: {:ok, GeoproxServer.Model.InsertKeyResponse.t} | {:error, Tesla.Env.t}
  def insert_key(connection, index, insert_key, _opts \\ []) do
    request =
      %{}
      |> method(:put)
      |> url("/api/v1/shard/#{index}")
      |> add_param(:body, :body, insert_key)
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {201, GeoproxServer.Model.InsertKeyResponse}
    ])
  end

  @doc """
  Insert multiple keys into index
  Inserts multiple keys into geospatial index

  ### Parameters

  - `connection` (GeoproxServer.Connection): Connection to server
  - `index` (String.t): Geospatial index name
  - `insert_key_batch` (InsertKeyBatch): 
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, GeoproxServer.Model.InsertKeyBatchResponse.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec insert_key_batch(Tesla.Env.client, String.t, GeoproxServer.Model.InsertKeyBatch.t, keyword()) :: {:ok, GeoproxServer.Model.InsertKeyBatchResponse.t} | {:error, Tesla.Env.t}
  def insert_key_batch(connection, index, insert_key_batch, _opts \\ []) do
    request =
      %{}
      |> method(:put)
      |> url("/api/v1/shard/#{index}/batch")
      |> add_param(:body, :body, insert_key_batch)
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {201, GeoproxServer.Model.InsertKeyBatchResponse}
    ])
  end

  @doc """
  Search index for objects nearby
  Search geospatial index for all keys within some distance

  ### Parameters

  - `connection` (GeoproxServer.Connection): Connection to server
  - `index` (String.t): Geospatial index name
  - `lat` (float()): Latitude
  - `lng` (float()): Longitude
  - `range` (integer()): Search radius in kilometers
  - `opts` (keyword): Optional parameters
    - `:count` (integer()): Maximum number of neighbors that can be returned (default 100)
    - `:sorted` (boolean()): If enabled neighbors will be sorted by distance, nearest to furthest (default false)

  ### Returns

  - `{:ok, GeoproxServer.Model.QueryRangeResponse.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec query_range(Tesla.Env.client, String.t, float(), float(), integer(), keyword()) :: {:ok, GeoproxServer.Model.QueryRangeResponse.t} | {:error, Tesla.Env.t}
  def query_range(connection, index, lat, lng, range, opts \\ []) do
    optional_params = %{
      :count => :query,
      :sorted => :query
    }

    request =
      %{}
      |> method(:get)
      |> url("/api/v1/shard/#{index}")
      |> add_param(:query, :lat, lat)
      |> add_param(:query, :lng, lng)
      |> add_param(:query, :range, range)
      |> add_optional_params(optional_params, opts)
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, GeoproxServer.Model.QueryRangeResponse}
    ])
  end

  @doc """
  Search multiple indices for objects nearby
  Search geospatial many indices for all keys within some distance

  ### Parameters

  - `connection` (GeoproxServer.Connection): Connection to server
  - `indices` ([String.t]): List of indices to search
  - `lat` (float()): Latitude
  - `lng` (float()): Longitude
  - `range` (integer()): Search radius in kilometers
  - `opts` (keyword): Optional parameters
    - `:count` (integer()): Maximum number of neighbors that can be returned (default 100)
    - `:sorted` (boolean()): If enabled neighbors will be sorted by distance, nearest to furthest (default false)

  ### Returns

  - `{:ok, GeoproxServer.Model.QueryRangeManyResponse.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec query_range_many(Tesla.Env.client, list(String.t), float(), float(), integer(), keyword()) :: {:ok, GeoproxServer.Model.QueryRangeManyResponse.t} | {:error, Tesla.Env.t}
  def query_range_many(connection, indices, lat, lng, range, opts \\ []) do
    optional_params = %{
      :count => :query,
      :sorted => :query
    }

    request =
      %{}
      |> method(:get)
      |> url("/api/v1/shard")
      |> add_param(:query, :indices, indices)
      |> add_param(:query, :lat, lat)
      |> add_param(:query, :lng, lng)
      |> add_param(:query, :range, range)
      |> add_optional_params(optional_params, opts)
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, GeoproxServer.Model.QueryRangeManyResponse}
    ])
  end

  @doc """
  Remove key from index
  Removes key from geospatial index

  ### Parameters

  - `connection` (GeoproxServer.Connection): Connection to server
  - `index` (String.t): Geospatial index name
  - `remove_key` (RemoveKey): 
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, GeoproxServer.Model.RemoveKeyResponse.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec remove_key(Tesla.Env.client, String.t, GeoproxServer.Model.RemoveKey.t, keyword()) :: {:ok, GeoproxServer.Model.RemoveKeyResponse.t} | {:error, Tesla.Env.t}
  def remove_key(connection, index, remove_key, _opts \\ []) do
    request =
      %{}
      |> method(:patch)
      |> url("/api/v1/shard/#{index}")
      |> add_param(:body, :body, remove_key)
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, GeoproxServer.Model.RemoveKeyResponse}
    ])
  end

  @doc """
  Remove multiple keys from index
  Removes multiple keys from geospatial index

  ### Parameters

  - `connection` (GeoproxServer.Connection): Connection to server
  - `index` (String.t): Geospatial index name
  - `remove_key_batch` (RemoveKeyBatch): 
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, GeoproxServer.Model.RemoveKeyBatchResponse.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec remove_key_batch(Tesla.Env.client, String.t, GeoproxServer.Model.RemoveKeyBatch.t, keyword()) :: {:ok, GeoproxServer.Model.RemoveKeyBatchResponse.t} | {:error, Tesla.Env.t}
  def remove_key_batch(connection, index, remove_key_batch, _opts \\ []) do
    request =
      %{}
      |> method(:patch)
      |> url("/api/v1/shard/#{index}/batch")
      |> add_param(:body, :body, remove_key_batch)
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, GeoproxServer.Model.RemoveKeyBatchResponse}
    ])
  end
end
