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

import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.pagination import AsyncPager, SyncPager
from ..core.request_options import RequestOptions
from ..types.get_refresh_token_response_content import GetRefreshTokenResponseContent
from ..types.get_refresh_tokens_paginated_response_content import GetRefreshTokensPaginatedResponseContent
from ..types.refresh_token_metadata import RefreshTokenMetadata
from ..types.refresh_token_response_content import RefreshTokenResponseContent
from ..types.update_refresh_token_response_content import UpdateRefreshTokenResponseContent
from .raw_client import AsyncRawRefreshTokensClient, RawRefreshTokensClient

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


class RefreshTokensClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawRefreshTokensClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawRefreshTokensClient
        """
        return self._raw_client

    def list(
        self,
        *,
        user_id: str,
        client_id: typing.Optional[str] = None,
        from_: typing.Optional[str] = None,
        take: typing.Optional[int] = 50,
        fields: typing.Optional[str] = None,
        include_fields: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SyncPager[RefreshTokenResponseContent, GetRefreshTokensPaginatedResponseContent]:
        """
        Retrieve a paginated list of refresh tokens for a specific user, with optional filtering by client ID. Results are sorted by credential_id ascending.

        Parameters
        ----------
        user_id : str
            ID of the user whose refresh tokens to retrieve. Required.

        client_id : typing.Optional[str]
            Filter results by client ID. Only valid when user_id is provided.

        from_ : typing.Optional[str]
            An opaque cursor from which to start the selection (exclusive). Expires after 24 hours. Obtained from the next property of a previous response.

        take : typing.Optional[int]
            Number of results per page. Defaults to 50.

        fields : typing.Optional[str]
            Comma-separated list of fields to include or exclude (based on value provided for include_fields) in the result. Leave empty to retrieve all fields.

        include_fields : typing.Optional[bool]
            Whether specified fields are to be included (true) or excluded (false).

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

        Returns
        -------
        SyncPager[RefreshTokenResponseContent, GetRefreshTokensPaginatedResponseContent]
            The refresh tokens were retrieved.

        Examples
        --------
        from auth0 import Auth0

        client = Auth0(
            token="YOUR_TOKEN",
        )
        response = client.refresh_tokens.list(
            user_id="user_id",
            client_id="client_id",
            from_="from",
            take=1,
            fields="fields",
            include_fields=True,
        )
        for item in response:
            yield item
        # alternatively, you can paginate page-by-page
        for page in response.iter_pages():
            yield page
        """
        return self._raw_client.list(
            user_id=user_id,
            client_id=client_id,
            from_=from_,
            take=take,
            fields=fields,
            include_fields=include_fields,
            request_options=request_options,
        )

    def revoke(
        self,
        *,
        ids: typing.Optional[typing.Sequence[str]] = OMIT,
        user_id: typing.Optional[str] = OMIT,
        client_id: typing.Optional[str] = OMIT,
        audience: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Revoke refresh tokens in bulk by ID list, user, user+client, or user+client+audience.

        Parameters
        ----------
        ids : typing.Optional[typing.Sequence[str]]
            Array of refresh token IDs to revoke. Limited to 100 at a time.

        user_id : typing.Optional[str]
            Revoke all refresh tokens for this user.

        client_id : typing.Optional[str]
            Revoke refresh tokens for this client. Must be paired with `user_id`; optionally narrowed further with `audience`.

        audience : typing.Optional[str]
            Resource server identifier (audience) to scope the revocation. Must be used with both `user_id` and `client_id`.

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

        Returns
        -------
        None

        Examples
        --------
        from auth0 import Auth0

        client = Auth0(
            token="YOUR_TOKEN",
        )
        client.refresh_tokens.revoke()
        """
        _response = self._raw_client.revoke(
            ids=ids, user_id=user_id, client_id=client_id, audience=audience, request_options=request_options
        )
        return _response.data

    def get(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> GetRefreshTokenResponseContent:
        """
        Retrieve refresh token information.

        Parameters
        ----------
        id : str
            ID refresh token to retrieve

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

        Returns
        -------
        GetRefreshTokenResponseContent
            The refresh token was retrieved

        Examples
        --------
        from auth0 import Auth0

        client = Auth0(
            token="YOUR_TOKEN",
        )
        client.refresh_tokens.get(
            id="id",
        )
        """
        _response = self._raw_client.get(id, request_options=request_options)
        return _response.data

    def delete(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
        """
        Delete a refresh token by its ID.

        Parameters
        ----------
        id : str
            ID of the refresh token to delete.

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

        Returns
        -------
        None

        Examples
        --------
        from auth0 import Auth0

        client = Auth0(
            token="YOUR_TOKEN",
        )
        client.refresh_tokens.delete(
            id="id",
        )
        """
        _response = self._raw_client.delete(id, request_options=request_options)
        return _response.data

    def update(
        self,
        id: str,
        *,
        refresh_token_metadata: typing.Optional[RefreshTokenMetadata] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpdateRefreshTokenResponseContent:
        """
        Update a refresh token by its ID.

        Parameters
        ----------
        id : str
            ID of the refresh token to update.

        refresh_token_metadata : typing.Optional[RefreshTokenMetadata]
            Metadata associated with the refresh token. Pass null or {} to remove all metadata.

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

        Returns
        -------
        UpdateRefreshTokenResponseContent
            Refresh token successfully updated.

        Examples
        --------
        from auth0 import Auth0

        client = Auth0(
            token="YOUR_TOKEN",
        )
        client.refresh_tokens.update(
            id="id",
        )
        """
        _response = self._raw_client.update(
            id, refresh_token_metadata=refresh_token_metadata, request_options=request_options
        )
        return _response.data


class AsyncRefreshTokensClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawRefreshTokensClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawRefreshTokensClient
        """
        return self._raw_client

    async def list(
        self,
        *,
        user_id: str,
        client_id: typing.Optional[str] = None,
        from_: typing.Optional[str] = None,
        take: typing.Optional[int] = 50,
        fields: typing.Optional[str] = None,
        include_fields: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncPager[RefreshTokenResponseContent, GetRefreshTokensPaginatedResponseContent]:
        """
        Retrieve a paginated list of refresh tokens for a specific user, with optional filtering by client ID. Results are sorted by credential_id ascending.

        Parameters
        ----------
        user_id : str
            ID of the user whose refresh tokens to retrieve. Required.

        client_id : typing.Optional[str]
            Filter results by client ID. Only valid when user_id is provided.

        from_ : typing.Optional[str]
            An opaque cursor from which to start the selection (exclusive). Expires after 24 hours. Obtained from the next property of a previous response.

        take : typing.Optional[int]
            Number of results per page. Defaults to 50.

        fields : typing.Optional[str]
            Comma-separated list of fields to include or exclude (based on value provided for include_fields) in the result. Leave empty to retrieve all fields.

        include_fields : typing.Optional[bool]
            Whether specified fields are to be included (true) or excluded (false).

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

        Returns
        -------
        AsyncPager[RefreshTokenResponseContent, GetRefreshTokensPaginatedResponseContent]
            The refresh tokens were retrieved.

        Examples
        --------
        import asyncio

        from auth0 import AsyncAuth0

        client = AsyncAuth0(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            response = await client.refresh_tokens.list(
                user_id="user_id",
                client_id="client_id",
                from_="from",
                take=1,
                fields="fields",
                include_fields=True,
            )
            async for item in response:
                yield item

            # alternatively, you can paginate page-by-page
            async for page in response.iter_pages():
                yield page


        asyncio.run(main())
        """
        return await self._raw_client.list(
            user_id=user_id,
            client_id=client_id,
            from_=from_,
            take=take,
            fields=fields,
            include_fields=include_fields,
            request_options=request_options,
        )

    async def revoke(
        self,
        *,
        ids: typing.Optional[typing.Sequence[str]] = OMIT,
        user_id: typing.Optional[str] = OMIT,
        client_id: typing.Optional[str] = OMIT,
        audience: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Revoke refresh tokens in bulk by ID list, user, user+client, or user+client+audience.

        Parameters
        ----------
        ids : typing.Optional[typing.Sequence[str]]
            Array of refresh token IDs to revoke. Limited to 100 at a time.

        user_id : typing.Optional[str]
            Revoke all refresh tokens for this user.

        client_id : typing.Optional[str]
            Revoke refresh tokens for this client. Must be paired with `user_id`; optionally narrowed further with `audience`.

        audience : typing.Optional[str]
            Resource server identifier (audience) to scope the revocation. Must be used with both `user_id` and `client_id`.

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

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from auth0 import AsyncAuth0

        client = AsyncAuth0(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.refresh_tokens.revoke()


        asyncio.run(main())
        """
        _response = await self._raw_client.revoke(
            ids=ids, user_id=user_id, client_id=client_id, audience=audience, request_options=request_options
        )
        return _response.data

    async def get(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> GetRefreshTokenResponseContent:
        """
        Retrieve refresh token information.

        Parameters
        ----------
        id : str
            ID refresh token to retrieve

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

        Returns
        -------
        GetRefreshTokenResponseContent
            The refresh token was retrieved

        Examples
        --------
        import asyncio

        from auth0 import AsyncAuth0

        client = AsyncAuth0(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.refresh_tokens.get(
                id="id",
            )


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

    async def delete(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
        """
        Delete a refresh token by its ID.

        Parameters
        ----------
        id : str
            ID of the refresh token to delete.

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

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from auth0 import AsyncAuth0

        client = AsyncAuth0(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.refresh_tokens.delete(
                id="id",
            )


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

    async def update(
        self,
        id: str,
        *,
        refresh_token_metadata: typing.Optional[RefreshTokenMetadata] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpdateRefreshTokenResponseContent:
        """
        Update a refresh token by its ID.

        Parameters
        ----------
        id : str
            ID of the refresh token to update.

        refresh_token_metadata : typing.Optional[RefreshTokenMetadata]
            Metadata associated with the refresh token. Pass null or {} to remove all metadata.

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

        Returns
        -------
        UpdateRefreshTokenResponseContent
            Refresh token successfully updated.

        Examples
        --------
        import asyncio

        from auth0 import AsyncAuth0

        client = AsyncAuth0(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.refresh_tokens.update(
                id="id",
            )


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