# -*- 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.derivatives_tickers_list import DerivativesTickersList
from coingeckopublicapiv3.models.derivatives_exchanges import DerivativesExchanges
from coingeckopublicapiv3.models.derivatives_exchanges_id import DerivativesExchangesID
from coingeckopublicapiv3.models.derivatives_exchanges_list import DerivativesExchangesList


class DerivativesController(BaseController):

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

    def derivatives_tickers(self):
        """Does a GET request to /derivatives.

        This endpoint allows you to **query all the tickers from derivatives
        exchanges on CoinGecko**

        Returns:
            DerivativesTickersList: Response from the API. List all derivative
                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('/derivatives')
            .http_method(HttpMethodEnum.GET)
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Or(Single('apiKeyAuth'), Single('apiKeyQueryParam')))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(DerivativesTickersList.from_dictionary)
        ).execute()

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

        This endpoint allows you to **query all the derivatives exchanges with
        related data (ID, name, open interest, ...) on CoinGecko**

        Args:
            order (Order4Enum, optional): use this to sort the order of
                responses, default: open_interest_btc_desc
            per_page (int, optional): total results per page
            page (int, optional): page through results, default: 1

        Returns:
            DerivativesExchanges: Response from the API. List all derivative
                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('/derivatives/exchanges')
            .http_method(HttpMethodEnum.GET)
            .query_param(Parameter()
                         .key('order')
                         .value(order))
            .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(DerivativesExchanges.from_dictionary)
        ).execute()

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

        This endpoint allows you to **query the derivatives exchange’s related
        data (ID, name, open interest, ...) based on the exchanges’ ID**

        Args:
            id (str): derivative exchange ID <br> *refers to
                [`/derivatives/exchanges/list`](/reference/derivatives-exchange
                s-list).
            include_tickers (IncludeTickersEnum, optional): include tickers
                data

        Returns:
            DerivativesExchangesID: Response from the API. Get derivative
                exchange 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('/derivatives/exchanges/{id}')
            .http_method(HttpMethodEnum.GET)
            .template_param(Parameter()
                            .key('id')
                            .value(id)
                            .should_encode(True))
            .query_param(Parameter()
                         .key('include_tickers')
                         .value(include_tickers))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Or(Single('apiKeyAuth'), Single('apiKeyQueryParam')))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(DerivativesExchangesID.from_dictionary)
        ).execute()

    def derivatives_exchanges_list(self):
        """Does a GET request to /derivatives/exchanges/list.

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

        Returns:
            DerivativesExchangesList: Response from the API. List all
                derivative exchanges name and identifier

        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('/derivatives/exchanges/list')
            .http_method(HttpMethodEnum.GET)
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Or(Single('apiKeyAuth'), Single('apiKeyQueryParam')))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(DerivativesExchangesList.from_dictionary)
        ).execute()
