from trimble.id._constants import PACKAGE_NAME
from .AnalyticsHttpClient import AnalyticsHttpClient
import pkg_resources  

class FixedTokenProvider:
    """
    A token provider that returns a fixed token
    """
    def __init__(self, token, productName = None):
        """
        Initialize FixedTokenProvider class

        :param token: Sets access token to FixedTokenProvider
        :param productName: Product name of the consuming application
        """
        self._token = token

        self._version = pkg_resources.require(PACKAGE_NAME)[0].version

        AnalyticsHttpClient.SendInitEvent(
            name=self.__class__.__name__, 
            client_name=PACKAGE_NAME, 
            client_version=self._version)

    async def retrieve_token(self):
        """
        Retrieves fixed token
        """
        AnalyticsHttpClient.SendMethodEvent(
            name=f"{self.__class__.__name__}_retrieve_token", 
            client_name=PACKAGE_NAME, 
            client_version=self._version)

        return self._token