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

defmodule CoinAPIIndexesRESTAPI.Api.Indexes do
  @moduledoc """
  API calls for all endpoints tagged `Indexes`.
  """

  alias CoinAPIIndexesRESTAPI.Connection
  import CoinAPIIndexesRESTAPI.RequestBuilder

  @doc """
  Returns all data inputs for a specific index definition

  ### Parameters

  - `connection` (CoinAPIIndexesRESTAPI.Connection): Connection to server
  - `index_definition_id` (String.t): 
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, [%IndexesIndexDefinitionInputData{}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec v1_indexdef_input_data_index_definition_id_all_get(Tesla.Env.client, String.t, keyword()) :: {:ok, [CoinAPIIndexesRESTAPI.Model.IndexesIndexDefinitionInputData.t]} | {:error, Tesla.Env.t}
  def v1_indexdef_input_data_index_definition_id_all_get(connection, index_definition_id, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/v1/indexdef/input-data/#{index_definition_id}/all")
      |> Enum.into([])

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

  @doc """
  Returns data inputs for certain index definition and time

  ### Parameters

  - `connection` (CoinAPIIndexesRESTAPI.Connection): Connection to server
  - `index_definition_id` (String.t): 
  - `opts` (keyword): Optional parameters
    - `:time` (DateTime.t): 
    - `:enabled_only` (boolean()): 
    - `:pending_only` (boolean()): 
    - `:filter_asset_id` (String.t): 
    - `:with_status_info` (boolean()): 

  ### Returns

  - `{:ok, [%IndexesIndexDefinitionSnapshotEntry{}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec v1_indexdef_input_data_index_definition_id_get(Tesla.Env.client, String.t, keyword()) :: {:ok, [CoinAPIIndexesRESTAPI.Model.IndexesIndexDefinitionSnapshotEntry.t]} | {:error, Tesla.Env.t}
  def v1_indexdef_input_data_index_definition_id_get(connection, index_definition_id, opts \\ []) do
    optional_params = %{
      :time => :query,
      :enabled_only => :query,
      :pending_only => :query,
      :filter_asset_id => :query,
      :with_status_info => :query
    }

    request =
      %{}
      |> method(:get)
      |> url("/v1/indexdef/input-data/#{index_definition_id}")
      |> add_optional_params(optional_params, opts)
      |> Enum.into([])

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

  @doc """
  Get all multi-asset weights

  ### Parameters

  - `connection` (CoinAPIIndexesRESTAPI.Connection): Connection to server
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, [%IndexesIndexMultiAssetWeight{}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec v1_indexdef_multiasset_get(Tesla.Env.client, keyword()) :: {:ok, [CoinAPIIndexesRESTAPI.Model.IndexesIndexMultiAssetWeight.t]} | {:error, Tesla.Env.t}
  def v1_indexdef_multiasset_get(connection, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/v1/indexdef/multiasset")
      |> Enum.into([])

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

  @doc """
  Get multi-asset weights for specific index

  ### Parameters

  - `connection` (CoinAPIIndexesRESTAPI.Connection): Connection to server
  - `index_id` (String.t): 
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, [%IndexesIndexMultiAssetWeight{}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec v1_indexdef_multiasset_index_id_get(Tesla.Env.client, String.t, keyword()) :: {:ok, [CoinAPIIndexesRESTAPI.Model.IndexesIndexMultiAssetWeight.t]} | {:error, Tesla.Env.t}
  def v1_indexdef_multiasset_index_id_get(connection, index_id, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/v1/indexdef/multiasset/#{index_id}")
      |> Enum.into([])

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

  @doc """
  List indexes

  ### Parameters

  - `connection` (CoinAPIIndexesRESTAPI.Connection): Connection to server
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, [%IndexesIndexIdentifier{}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec v1_indexes_get(Tesla.Env.client, keyword()) :: {:ok, [CoinAPIIndexesRESTAPI.Model.IndexesIndexIdentifier.t]} | {:error, Tesla.Env.t}
  def v1_indexes_get(connection, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/v1/indexes")
      |> Enum.into([])

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

  @doc """
  Current Index Values for index definition

  ### Parameters

  - `connection` (CoinAPIIndexesRESTAPI.Connection): Connection to server
  - `index_definition_id` (String.t): 
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, [%IndexesIndexDefinitionSnapshotEntry{}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec v1_indexes_index_definition_id_current_snapshot_get(Tesla.Env.client, String.t, keyword()) :: {:ok, [CoinAPIIndexesRESTAPI.Model.IndexesIndexDefinitionSnapshotEntry.t]} | {:error, Tesla.Env.t}
  def v1_indexes_index_definition_id_current_snapshot_get(connection, index_definition_id, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/v1/indexes/#{index_definition_id}/currentSnapshot")
      |> Enum.into([])

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

  @doc """
  Historical Index Values for index definition

  ### Parameters

  - `connection` (CoinAPIIndexesRESTAPI.Connection): Connection to server
  - `index_definition_id` (String.t): 
  - `opts` (keyword): Optional parameters
    - `:time` (DateTime.t): 

  ### Returns

  - `{:ok, [%IndexesIndexDefinitionSnapshotEntry{}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec v1_indexes_index_definition_id_history_snapshot_get(Tesla.Env.client, String.t, keyword()) :: {:ok, [CoinAPIIndexesRESTAPI.Model.IndexesIndexDefinitionSnapshotEntry.t]} | {:error, Tesla.Env.t}
  def v1_indexes_index_definition_id_history_snapshot_get(connection, index_definition_id, opts \\ []) do
    optional_params = %{
      :time => :query
    }

    request =
      %{}
      |> method(:get)
      |> url("/v1/indexes/#{index_definition_id}/historySnapshot")
      |> add_optional_params(optional_params, opts)
      |> Enum.into([])

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

  @doc """
  Current Index Value

  ### Parameters

  - `connection` (CoinAPIIndexesRESTAPI.Connection): Connection to server
  - `index_id` (String.t): 
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, CoinAPIIndexesRESTAPI.Model.IndexesIndexValue.t}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec v1_indexes_index_id_current_get(Tesla.Env.client, String.t, keyword()) :: {:ok, CoinAPIIndexesRESTAPI.Model.IndexesIndexValue.t} | {:error, Tesla.Env.t}
  def v1_indexes_index_id_current_get(connection, index_id, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/v1/indexes/#{index_id}/current")
      |> Enum.into([])

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

  @doc """
  Historical Index Value w/Composition

  ### Parameters

  - `connection` (CoinAPIIndexesRESTAPI.Connection): Connection to server
  - `index_id` (String.t): 
  - `opts` (keyword): Optional parameters
    - `:time_start` (DateTime.t): 
    - `:time_end` (DateTime.t): 
    - `:limit` (integer()): 

  ### Returns

  - `{:ok, [%IndexesIndexValue{}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec v1_indexes_index_id_history_get(Tesla.Env.client, String.t, keyword()) :: {:ok, [CoinAPIIndexesRESTAPI.Model.IndexesIndexValue.t]} | {:error, Tesla.Env.t}
  def v1_indexes_index_id_history_get(connection, index_id, opts \\ []) do
    optional_params = %{
      :time_start => :query,
      :time_end => :query,
      :limit => :query
    }

    request =
      %{}
      |> method(:get)
      |> url("/v1/indexes/#{index_id}/history")
      |> add_optional_params(optional_params, opts)
      |> Enum.into([])

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

  @doc """
  Timeseries Index Value

  ### Parameters

  - `connection` (CoinAPIIndexesRESTAPI.Connection): Connection to server
  - `index_id` (String.t): 
  - `period_id` (String.t): Identifier of requested timeseries period (e.g. `5SEC` or `1DAY`)
  - `time_start` (String.t): Timeseries starting time in ISO 8601
  - `time_end` (String.t): Timeseries ending time in ISO 8601
  - `opts` (keyword): Optional parameters
    - `:limit` (integer()): Amount of items to return (optional, mininum is 1, maximum is 100000, default value is 100, if the parameter is used then every 100 output items are counted as one request)

  ### Returns

  - `{:ok, [%IndexesIndexTimeseriesItem{}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec v1_indexes_index_id_timeseries_get(Tesla.Env.client, String.t, String.t, String.t, String.t, keyword()) :: {:ok, [CoinAPIIndexesRESTAPI.Model.IndexesIndexTimeseriesItem.t]} | {:error, Tesla.Env.t}
  def v1_indexes_index_id_timeseries_get(connection, index_id, period_id, time_start, time_end, opts \\ []) do
    optional_params = %{
      :limit => :query
    }

    request =
      %{}
      |> method(:get)
      |> url("/v1/indexes/#{index_id}/timeseries")
      |> add_param(:query, :period_id, period_id)
      |> add_param(:query, :time_start, time_start)
      |> add_param(:query, :time_end, time_end)
      |> add_optional_params(optional_params, opts)
      |> Enum.into([])

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