# This file was auto-generated by Fern from our API Definition.

import typing

from ....core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ....core.request_options import RequestOptions
from ....types.grant_v1response import GrantV1Response
from .raw_client import AsyncRawTokensClient, RawTokensClient

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class TokensClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawTokensClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> RawTokensClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawTokensClient
        """
        return self._raw_client

    def grant(
        self, *, ttl_seconds: typing.Optional[float] = OMIT, request_options: typing.Optional[RequestOptions] = None
    ) -> GrantV1Response:
        """
        Generates a temporary JSON Web Token (JWT) with a 30-second (by default) TTL and usage::write permission for core voice APIs, requiring an API key with Member or higher authorization. Tokens created with this endpoint will not work with the Manage APIs.

        Parameters
        ----------
        ttl_seconds : typing.Optional[float]
            Time to live in seconds for the token. Defaults to 30 seconds.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        GrantV1Response
            Grant response

        Examples
        --------
        from deepgram import DeepgramClient

        client = DeepgramClient(
            api_key="YOUR_API_KEY",
        )
        client.auth.v1.tokens.grant()
        """
        _response = self._raw_client.grant(ttl_seconds=ttl_seconds, request_options=request_options)
        return _response.data


class AsyncTokensClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawTokensClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> AsyncRawTokensClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawTokensClient
        """
        return self._raw_client

    async def grant(
        self, *, ttl_seconds: typing.Optional[float] = OMIT, request_options: typing.Optional[RequestOptions] = None
    ) -> GrantV1Response:
        """
        Generates a temporary JSON Web Token (JWT) with a 30-second (by default) TTL and usage::write permission for core voice APIs, requiring an API key with Member or higher authorization. Tokens created with this endpoint will not work with the Manage APIs.

        Parameters
        ----------
        ttl_seconds : typing.Optional[float]
            Time to live in seconds for the token. Defaults to 30 seconds.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        GrantV1Response
            Grant response

        Examples
        --------
        import asyncio

        from deepgram import AsyncDeepgramClient

        client = AsyncDeepgramClient(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.auth.v1.tokens.grant()


        asyncio.run(main())
        """
        _response = await self._raw_client.grant(ttl_seconds=ttl_seconds, request_options=request_options)
        return _response.data
