# -*- 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.coins_data_base import CoinsDataBase
from coingeckopublicapiv3.models.coins_market_chart import CoinsMarketChart
from coingeckopublicapiv3.models.coins_market_chart_range import CoinsMarketChartRange


class ContractController(BaseController):

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

    def coins_contract_address(self,
                               id,
                               contract_address):
        """Does a GET request to /coins/{id}/contract/{contract_address}.

        This endpoint allows you to **query all the metadata (image, websites,
        socials, description, contract address, etc.) and market data (price,
        ATH, exchange tickers, etc.) of a coin from the CoinGecko coin page
        based on an asset platform and a particular token contract address**

        Args:
            id (str): asset platform ID <br> *refers to
                [`/asset_platforms`](/reference/asset-platforms-list).
            contract_address (str): the contract address of token

        Returns:
            CoinsDataBase: Response from the API. Get current data for a coin

        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('/coins/{id}/contract/{contract_address}')
            .http_method(HttpMethodEnum.GET)
            .template_param(Parameter()
                            .key('id')
                            .value(id)
                            .should_encode(True))
            .template_param(Parameter()
                            .key('contract_address')
                            .value(contract_address)
                            .should_encode(True))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Or(Single('apiKeyAuth'), Single('apiKeyQueryParam')))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(CoinsDataBase.from_dictionary)
        ).execute()

    def contract_address_market_chart(self,
                                      id,
                                      contract_address,
                                      vs_currency,
                                      days,
                                      interval=None,
                                      precision=None):
        """Does a GET request to /coins/{id}/contract/{contract_address}/market_chart.

        This endpoint allows you to **get the historical chart data including
        time in UNIX, price, market cap and 24hr volume based on asset
        platform and particular token contract address**

        Args:
            id (str): asset platform ID <br> *refers to
                [`/asset_platforms`](/reference/asset-platforms-list).
            contract_address (str): the contract address of token
            vs_currency (str): target currency of market data <br> *refers to
                [`/simple/supported_vs_currencies`](/reference/simple-supported
                -currencies).
            days (str): data up to number of days ago <br> You may use any
                integer for number of days
            interval (IntervalEnum, optional): data interval, leave empty for
                auto granularity Possible value: daily
            precision (PrecisionEnum, optional): decimal place for currency
                price value

        Returns:
            CoinsMarketChart: Response from the API. Get historical market
                data include price, market cap, and 24hr volume

        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('/coins/{id}/contract/{contract_address}/market_chart')
            .http_method(HttpMethodEnum.GET)
            .template_param(Parameter()
                            .key('id')
                            .value(id)
                            .should_encode(True))
            .template_param(Parameter()
                            .key('contract_address')
                            .value(contract_address)
                            .should_encode(True))
            .query_param(Parameter()
                         .key('vs_currency')
                         .value(vs_currency))
            .query_param(Parameter()
                         .key('days')
                         .value(days))
            .query_param(Parameter()
                         .key('interval')
                         .value(interval))
            .query_param(Parameter()
                         .key('precision')
                         .value(precision))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Or(Single('apiKeyAuth'), Single('apiKeyQueryParam')))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(CoinsMarketChart.from_dictionary)
        ).execute()

    def contract_address_market_chart_range(self,
                                            id,
                                            contract_address,
                                            vs_currency,
                                            mfrom,
                                            to,
                                            precision=None):
        """Does a GET request to /coins/{id}/contract/{contract_address}/market_chart/range.

        This endpoint allows you to **get the historical chart data within
        certain time range in UNIX along with price, market cap and 24hr
        volume based on asset platform and particular token contract address**

        Args:
            id (str): asset platform ID <br> *refers to
                [`/asset_platforms`](/reference/asset-platforms-list)
            contract_address (str): the contract address of token
            vs_currency (str): target currency of market data <br> *refers to
                [`/simple/supported_vs_currencies`](/reference/simple-supported
                -currencies).
            mfrom (int): starting date in UNIX timestamp
            to (int): ending date in UNIX timestamp
            precision (PrecisionEnum, optional): decimal place for currency
                price value

        Returns:
            CoinsMarketChartRange: Response from the API. Get historical
                market data include price, market cap, and 24hr volume

        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('/coins/{id}/contract/{contract_address}/market_chart/range')
            .http_method(HttpMethodEnum.GET)
            .template_param(Parameter()
                            .key('id')
                            .value(id)
                            .should_encode(True))
            .template_param(Parameter()
                            .key('contract_address')
                            .value(contract_address)
                            .should_encode(True))
            .query_param(Parameter()
                         .key('vs_currency')
                         .value(vs_currency))
            .query_param(Parameter()
                         .key('from')
                         .value(mfrom))
            .query_param(Parameter()
                         .key('to')
                         .value(to))
            .query_param(Parameter()
                         .key('precision')
                         .value(precision))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Or(Single('apiKeyAuth'), Single('apiKeyQueryParam')))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(CoinsMarketChartRange.from_dictionary)
        ).execute()
