# 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.lseapi_token_create import LseapiTokenCreate
from ..types.lseapi_token_list import LseapiTokenList
from ..types.token_refresh_response import TokenRefreshResponse
from ..types.token_rotate_response import TokenRotateResponse
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 list(
        self, *, ordering: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[LseapiTokenList]:
        """
        List all API tokens for the current user.

        Parameters
        ----------
        ordering : typing.Optional[str]
            Which field to use when ordering the results.

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

        Returns
        -------
        typing.List[LseapiTokenList]


        Examples
        --------
        from label_studio_sdk import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.tokens.list()
        """
        _response = self._raw_client.list(ordering=ordering, request_options=request_options)
        return _response.data

    def create(self, *, request_options: typing.Optional[RequestOptions] = None) -> LseapiTokenCreate:
        """
        Create a new API token for the current user.

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

        Returns
        -------
        LseapiTokenCreate


        Examples
        --------
        from label_studio_sdk import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.tokens.create()
        """
        _response = self._raw_client.create(request_options=request_options)
        return _response.data

    def blacklist(
        self, *, refresh: str, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.Dict[str, typing.Any]:
        """
        Adds a JWT refresh token to the blacklist, preventing it from being used to obtain new access tokens.

        Parameters
        ----------
        refresh : str

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

        Returns
        -------
        typing.Dict[str, typing.Any]


        Examples
        --------
        from label_studio_sdk import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.tokens.blacklist(
            refresh="refresh",
        )
        """
        _response = self._raw_client.blacklist(refresh=refresh, request_options=request_options)
        return _response.data

    def refresh(self, *, refresh: str, request_options: typing.Optional[RequestOptions] = None) -> TokenRefreshResponse:
        """
        Get a new access token, using a refresh token.

        Parameters
        ----------
        refresh : str

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

        Returns
        -------
        TokenRefreshResponse


        Examples
        --------
        from label_studio_sdk import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.tokens.refresh(
            refresh="refresh",
        )
        """
        _response = self._raw_client.refresh(refresh=refresh, request_options=request_options)
        return _response.data

    def rotate(self, *, refresh: str, request_options: typing.Optional[RequestOptions] = None) -> TokenRotateResponse:
        """
        Creates a new JWT refresh token and blacklists the current one.

        Parameters
        ----------
        refresh : str

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

        Returns
        -------
        TokenRotateResponse


        Examples
        --------
        from label_studio_sdk import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.tokens.rotate(
            refresh="refresh",
        )
        """
        _response = self._raw_client.rotate(refresh=refresh, 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 list(
        self, *, ordering: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[LseapiTokenList]:
        """
        List all API tokens for the current user.

        Parameters
        ----------
        ordering : typing.Optional[str]
            Which field to use when ordering the results.

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

        Returns
        -------
        typing.List[LseapiTokenList]


        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.tokens.list()


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

    async def create(self, *, request_options: typing.Optional[RequestOptions] = None) -> LseapiTokenCreate:
        """
        Create a new API token for the current user.

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

        Returns
        -------
        LseapiTokenCreate


        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.tokens.create()


        asyncio.run(main())
        """
        _response = await self._raw_client.create(request_options=request_options)
        return _response.data

    async def blacklist(
        self, *, refresh: str, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.Dict[str, typing.Any]:
        """
        Adds a JWT refresh token to the blacklist, preventing it from being used to obtain new access tokens.

        Parameters
        ----------
        refresh : str

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

        Returns
        -------
        typing.Dict[str, typing.Any]


        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.tokens.blacklist(
                refresh="refresh",
            )


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

    async def refresh(
        self, *, refresh: str, request_options: typing.Optional[RequestOptions] = None
    ) -> TokenRefreshResponse:
        """
        Get a new access token, using a refresh token.

        Parameters
        ----------
        refresh : str

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

        Returns
        -------
        TokenRefreshResponse


        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.tokens.refresh(
                refresh="refresh",
            )


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

    async def rotate(
        self, *, refresh: str, request_options: typing.Optional[RequestOptions] = None
    ) -> TokenRotateResponse:
        """
        Creates a new JWT refresh token and blacklists the current one.

        Parameters
        ----------
        refresh : str

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

        Returns
        -------
        TokenRotateResponse


        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.tokens.rotate(
                refresh="refresh",
            )


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