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

defmodule CoinAPIMarketDataRESTAPI.Api.MetricsV2 do
  @moduledoc """
  API calls for all endpoints tagged `MetricsV2`.
  """

  alias CoinAPIMarketDataRESTAPI.Connection
  import CoinAPIMarketDataRESTAPI.RequestBuilder

  @doc """
  Historical metrics for the asset
  Get asset metrics history.

  ### Parameters

  - `connection` (CoinAPIMarketDataRESTAPI.Connection): Connection to server
  - `metric_id` (String.t): Metric identifier (e.g., `TVL`, `STABLES_BRIDGED_USD`)
  - `asset_id` (String.t): Asset identifier (e.g., `USDC`, `USDT`)
  - `opts` (keyword): Optional parameters
    - `:time_start` (DateTime.t): Starting time in ISO 8601
    - `:time_end` (DateTime.t): Ending time in ISO 8601
    - `:time_format` (String.t): If set, returned values will be in unix timestamp format (valid values: unix_sec, unix_millisec, unix_microsec, unix_nanosec)
    - `:period_id` (String.t): Identifier of requested timeseries period (e.g. `1MIN` or `2MTH`), default value is `1MIN`
    - `: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, [%map(){}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec v2_metrics_asset_history_get(Tesla.Env.client, String.t, String.t, keyword()) :: {:ok, nil} | {:ok, [map()]} | {:error, Tesla.Env.t}
  def v2_metrics_asset_history_get(connection, metric_id, asset_id, opts \\ []) do
    optional_params = %{
      :time_start => :query,
      :time_end => :query,
      :time_format => :query,
      :period_id => :query,
      :limit => :query
    }

    request =
      %{}
      |> method(:get)
      |> url("/v2/metrics/asset/history")
      |> add_param(:query, :metric_id, metric_id)
      |> add_param(:query, :asset_id, asset_id)
      |> add_optional_params(optional_params, opts)
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, []},
      {400, false},
      {500, false}
    ])
  end

  @doc """
  Listing of metrics available for specific asset
  Get all metrics that are actually available for the specified asset.

  ### Parameters

  - `connection` (CoinAPIMarketDataRESTAPI.Connection): Connection to server
  - `asset_id` (String.t): Asset identifier (e.g., USDC, USDT)
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, [%V1MetricInfo{}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec v2_metrics_asset_listing_get(Tesla.Env.client, String.t, keyword()) :: {:ok, [CoinAPIMarketDataRESTAPI.Model.V1MetricInfo.t]} | {:error, Tesla.Env.t}
  def v2_metrics_asset_listing_get(connection, asset_id, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/v2/metrics/asset/listing")
      |> add_param(:query, :asset_id, asset_id)
      |> Enum.into([])

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

  @doc """
  Historical metrics for the chain
  Get chain metrics history.

  ### Parameters

  - `connection` (CoinAPIMarketDataRESTAPI.Connection): Connection to server
  - `metric_id` (String.t): Metric identifier (e.g., `TVL`, `STABLES_BRIDGED_USD`)
  - `chain_id` (String.t): Chain identifier (e.g., `Ethereum`, `Arbitrum`)
  - `opts` (keyword): Optional parameters
    - `:time_start` (DateTime.t): Starting time in ISO 8601
    - `:time_end` (DateTime.t): Ending time in ISO 8601
    - `:time_format` (String.t): If set, returned values will be in unix timestamp format (valid values: unix_sec, unix_millisec, unix_microsec, unix_nanosec)
    - `:period_id` (String.t): Identifier of requested timeseries period (e.g. `1MIN` or `2MTH`), default value is `1MIN`
    - `: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, [%map(){}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec v2_metrics_chain_history_get(Tesla.Env.client, String.t, String.t, keyword()) :: {:ok, nil} | {:ok, [map()]} | {:error, Tesla.Env.t}
  def v2_metrics_chain_history_get(connection, metric_id, chain_id, opts \\ []) do
    optional_params = %{
      :time_start => :query,
      :time_end => :query,
      :time_format => :query,
      :period_id => :query,
      :limit => :query
    }

    request =
      %{}
      |> method(:get)
      |> url("/v2/metrics/chain/history")
      |> add_param(:query, :metric_id, metric_id)
      |> add_param(:query, :chain_id, chain_id)
      |> add_optional_params(optional_params, opts)
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, []},
      {400, false},
      {500, false}
    ])
  end

  @doc """
  Listing of metrics available for specific chain
  Get all metrics that are actually available for the specified blockchain chain.

  ### Parameters

  - `connection` (CoinAPIMarketDataRESTAPI.Connection): Connection to server
  - `chain_id` (String.t): Chain identifier (e.g., ETHEREUM, ARBITRUM)
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, [%V1MetricInfo{}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec v2_metrics_chain_listing_get(Tesla.Env.client, String.t, keyword()) :: {:ok, [CoinAPIMarketDataRESTAPI.Model.V1MetricInfo.t]} | {:error, Tesla.Env.t}
  def v2_metrics_chain_listing_get(connection, chain_id, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/v2/metrics/chain/listing")
      |> add_param(:query, :chain_id, chain_id)
      |> Enum.into([])

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

  @doc """
  Historical metrics for the exchange
  Get exchange metrics history.

  ### Parameters

  - `connection` (CoinAPIMarketDataRESTAPI.Connection): Connection to server
  - `metric_id` (String.t): Metric identifier (e.g., `TVL`, `STABLES_BRIDGED_USD`)
  - `exchange_id` (String.t): Exchange identifier (e.g., `BINANCE`, `UNISWAP-V3-ETHEREUM`)
  - `opts` (keyword): Optional parameters
    - `:time_start` (DateTime.t): Starting time in ISO 8601
    - `:time_end` (DateTime.t): Ending time in ISO 8601
    - `:time_format` (String.t): If set, returned values will be in unix timestamp format (valid values: unix_sec, unix_millisec, unix_microsec, unix_nanosec)
    - `:period_id` (String.t): Identifier of requested timeseries period (e.g. `1MIN` or `2MTH`), default value is `1MIN`
    - `: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, [%map(){}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec v2_metrics_exchange_history_get(Tesla.Env.client, String.t, String.t, keyword()) :: {:ok, nil} | {:ok, [map()]} | {:error, Tesla.Env.t}
  def v2_metrics_exchange_history_get(connection, metric_id, exchange_id, opts \\ []) do
    optional_params = %{
      :time_start => :query,
      :time_end => :query,
      :time_format => :query,
      :period_id => :query,
      :limit => :query
    }

    request =
      %{}
      |> method(:get)
      |> url("/v2/metrics/exchange/history")
      |> add_param(:query, :metric_id, metric_id)
      |> add_param(:query, :exchange_id, exchange_id)
      |> add_optional_params(optional_params, opts)
      |> Enum.into([])

    connection
    |> Connection.request(request)
    |> evaluate_response([
      {200, []},
      {400, false},
      {500, false}
    ])
  end

  @doc """
  Listing of metrics available for specific exchange
  Get all metrics that are actually available for the specified exchange.

  ### Parameters

  - `connection` (CoinAPIMarketDataRESTAPI.Connection): Connection to server
  - `exchange_id` (String.t): Exchange identifier (e.g., BINANCE, UNISWAP-V3-ETHEREUM)
  - `opts` (keyword): Optional parameters

  ### Returns

  - `{:ok, [%V1MetricInfo{}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec v2_metrics_exchange_listing_get(Tesla.Env.client, String.t, keyword()) :: {:ok, [CoinAPIMarketDataRESTAPI.Model.V1MetricInfo.t]} | {:error, Tesla.Env.t}
  def v2_metrics_exchange_listing_get(connection, exchange_id, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/v2/metrics/exchange/listing")
      |> add_param(:query, :exchange_id, exchange_id)
      |> Enum.into([])

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

  @doc """
  Listing of all supported metrics
  Get all metrics available in the system.

  ### Parameters

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

  ### Returns

  - `{:ok, [%V1MetricInfo{}, ...]}` on success
  - `{:error, Tesla.Env.t}` on failure
  """
  @spec v2_metrics_listing_get(Tesla.Env.client, keyword()) :: {:ok, [CoinAPIMarketDataRESTAPI.Model.V1MetricInfo.t]} | {:error, Tesla.Env.t}
  def v2_metrics_listing_get(connection, _opts \\ []) do
    request =
      %{}
      |> method(:get)
      |> url("/v2/metrics/listing")
      |> Enum.into([])

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