# -*- coding: utf-8 -*-

"""
coingeckopublicapiv3

This file was automatically generated by APIMATIC v3.0 (
 https://www.apimatic.io ).
"""

from coingeckopublicapiv3.api_helper import APIHelper
from coingeckopublicapiv3.configuration import Server
from coingeckopublicapiv3.controllers.base_controller import BaseController
from apimatic_core.request_builder import RequestBuilder
from apimatic_core.response_handler import ResponseHandler
from apimatic_core.types.parameter import Parameter
from coingeckopublicapiv3.http.http_method_enum import HttpMethodEnum
from apimatic_core.authentication.multiple.single_auth import Single
from apimatic_core.authentication.multiple.or_auth_group import Or
from coingeckopublicapiv3.models.exchanges import Exchanges
from coingeckopublicapiv3.models.exchanges_list import ExchangesList
from coingeckopublicapiv3.models.exchange_data import ExchangeData
from coingeckopublicapiv3.models.coins_tickers import CoinsTickers


class ExchangesController(BaseController):

    """A Controller to access Endpoints in the coingeckopublicapiv3 API."""
    def __init__(self, config):
        super(ExchangesController, self).__init__(config)

    def exchanges(self,
                  per_page=None,
                  page=None):
        """Does a GET request to /exchanges.

        This endpoint allows you to **query all the supported exchanges with
        exchanges’ data (ID, name, country, ...) that have active trading
        volumes on CoinGecko**

        Args:
            per_page (int, optional): total results per page, default: 100
                <br> Valid values: 1...250
            page (int, optional): page through results, default: 1

        Returns:
            Exchanges: Response from the API. List all exchanges

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path('/exchanges')
            .http_method(HttpMethodEnum.GET)
            .query_param(Parameter()
                         .key('per_page')
                         .value(per_page))
            .query_param(Parameter()
                         .key('page')
                         .value(page))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Or(Single('apiKeyAuth'), Single('apiKeyQueryParam')))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(Exchanges.from_dictionary)
        ).execute()

    def exchanges_list(self,
                       status=None):
        """Does a GET request to /exchanges/list.

        This endpoint allows you to **query all the exchanges with ID and
        name**

        Args:
            status (StatusEnum, optional): filter by status of exchanges,
                default: active

        Returns:
            ExchangesList: Response from the API. List all exchanges with ID
                and name

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path('/exchanges/list')
            .http_method(HttpMethodEnum.GET)
            .query_param(Parameter()
                         .key('status')
                         .value(status))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Or(Single('apiKeyAuth'), Single('apiKeyQueryParam')))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(ExchangesList.from_dictionary)
        ).execute()

    def exchanges_id(self,
                     id,
                     dex_pair_format=None):
        """Does a GET request to /exchanges/{id}.

        This endpoint allows you to **query exchange’s data (name, year
        established, country, ...), exchange volume in BTC and top 100 tickers
        based on exchange’s ID**

        Args:
            id (str): exchange ID <br> *refers to
                [`/exchanges/list`](/reference/exchanges-list).
            dex_pair_format (DexPairFormatEnum, optional): set to `symbol` to
                display DEX pair base and target as symbols, default:
                `contract_address`

        Returns:
            ExchangeData: Response from the API. Get exchange volume in BTC
                and top 100 tickers only

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path('/exchanges/{id}')
            .http_method(HttpMethodEnum.GET)
            .template_param(Parameter()
                            .key('id')
                            .value(id)
                            .should_encode(True))
            .query_param(Parameter()
                         .key('dex_pair_format')
                         .value(dex_pair_format))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Or(Single('apiKeyAuth'), Single('apiKeyQueryParam')))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(ExchangeData.from_dictionary)
        ).execute()

    def exchanges_id_tickers(self,
                             id,
                             coin_ids=None,
                             include_exchange_logo=None,
                             page=None,
                             depth=None,
                             order=None,
                             dex_pair_format=None):
        """Does a GET request to /exchanges/{id}/tickers.

        This endpoint allows you to **query exchange's tickers based on
        exchange’s ID**

        Args:
            id (str): exchange ID <br> *refers to
                [`/exchanges/list`](/reference/exchanges-list).
            coin_ids (str, optional): filter tickers by coin IDs,
                comma-separated if querying more than 1 coin <br> *refers to
                [`/coins/list`](/reference/coins-list).
            include_exchange_logo (bool, optional): include exchange logo,
                default: false
            page (int, optional): page through results
            depth (bool, optional): include 2% orderbook depth (Example:
                cost_to_move_up_usd & cost_to_move_down_usd),default: false
            order (Order3Enum, optional): use this to sort the order of
                responses, default: trust_score_desc
            dex_pair_format (DexPairFormatEnum, optional): set to `symbol` to
                display DEX pair base and target as symbols, default:
                `contract_address`

        Returns:
            CoinsTickers: Response from the API. Get exchange tickers

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path('/exchanges/{id}/tickers')
            .http_method(HttpMethodEnum.GET)
            .template_param(Parameter()
                            .key('id')
                            .value(id)
                            .should_encode(True))
            .query_param(Parameter()
                         .key('coin_ids')
                         .value(coin_ids))
            .query_param(Parameter()
                         .key('include_exchange_logo')
                         .value(include_exchange_logo))
            .query_param(Parameter()
                         .key('page')
                         .value(page))
            .query_param(Parameter()
                         .key('depth')
                         .value(depth))
            .query_param(Parameter()
                         .key('order')
                         .value(order))
            .query_param(Parameter()
                         .key('dex_pair_format')
                         .value(dex_pair_format))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Or(Single('apiKeyAuth'), Single('apiKeyQueryParam')))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(CoinsTickers.from_dictionary)
        ).execute()

    def exchanges_id_volume_chart(self,
                                  id,
                                  days):
        """Does a GET request to /exchanges/{id}/volume_chart.

        This endpoint allows you to **query the historical volume chart data
        with time in UNIX and trading volume data in BTC based on exchange’s
        ID**

        Args:
            id (str): exchange ID or derivatives exchange ID <br> *refers to
                [`/exchanges/list`](/reference/exchanges-list) or
                [`/derivatives/exchanges/list`](/reference/derivatives-exchange
                s-list).
            days (DaysEnum): data up to number of days ago

        Returns:
            List[float]: Response from the API. Get exchange volume chart data

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path('/exchanges/{id}/volume_chart')
            .http_method(HttpMethodEnum.GET)
            .template_param(Parameter()
                            .key('id')
                            .value(id)
                            .should_encode(True))
            .query_param(Parameter()
                         .key('days')
                         .value(days))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Or(Single('apiKeyAuth'), Single('apiKeyQueryParam')))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
        ).execute()
