# 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.list_user_effective_permission_role_sources_response_content import (
    ListUserEffectivePermissionRoleSourcesResponseContent,
)
from .....types.user_effective_permission_role_source_response_content import (
    UserEffectivePermissionRoleSourceResponseContent,
)
from .raw_client import AsyncRawRolesClient, RawRolesClient


class RolesClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawRolesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawRolesClient
        """
        return self._raw_client

    def list(
        self,
        id: str,
        *,
        resource_server_identifier: str,
        permission_name: str,
        from_: typing.Optional[str] = None,
        take: typing.Optional[int] = 50,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SyncPager[
        UserEffectivePermissionRoleSourceResponseContent, ListUserEffectivePermissionRoleSourcesResponseContent
    ]:
        """
        Lists the roles which grant the user a given permission, including roles assigned directly to the user and those inherited through group memberships.

        Parameters
        ----------
        id : str
            ID of the user to retrieve the permissions for.

        resource_server_identifier : str
            The identifier of the resource server for which to calculate user permissions.

        permission_name : str
            Name of this permission

        from_ : typing.Optional[str]
            Optional Id from which to start selection.

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

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

        Returns
        -------
        SyncPager[UserEffectivePermissionRoleSourceResponseContent, ListUserEffectivePermissionRoleSourcesResponseContent]
            User's effective permission role sources successfully retrieved.

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

        client = Auth0(
            token="YOUR_TOKEN",
        )
        response = client.users.effective_permissions.sources.roles.list(
            id="id",
            from_="from",
            take=1,
            resource_server_identifier="resource_server_identifier",
            permission_name="permission_name",
        )
        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(
            id,
            resource_server_identifier=resource_server_identifier,
            permission_name=permission_name,
            from_=from_,
            take=take,
            request_options=request_options,
        )


class AsyncRolesClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawRolesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawRolesClient
        """
        return self._raw_client

    async def list(
        self,
        id: str,
        *,
        resource_server_identifier: str,
        permission_name: str,
        from_: typing.Optional[str] = None,
        take: typing.Optional[int] = 50,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncPager[
        UserEffectivePermissionRoleSourceResponseContent, ListUserEffectivePermissionRoleSourcesResponseContent
    ]:
        """
        Lists the roles which grant the user a given permission, including roles assigned directly to the user and those inherited through group memberships.

        Parameters
        ----------
        id : str
            ID of the user to retrieve the permissions for.

        resource_server_identifier : str
            The identifier of the resource server for which to calculate user permissions.

        permission_name : str
            Name of this permission

        from_ : typing.Optional[str]
            Optional Id from which to start selection.

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

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

        Returns
        -------
        AsyncPager[UserEffectivePermissionRoleSourceResponseContent, ListUserEffectivePermissionRoleSourcesResponseContent]
            User's effective permission role sources successfully retrieved.

        Examples
        --------
        import asyncio

        from auth0 import AsyncAuth0

        client = AsyncAuth0(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            response = await client.users.effective_permissions.sources.roles.list(
                id="id",
                from_="from",
                take=1,
                resource_server_identifier="resource_server_identifier",
                permission_name="permission_name",
            )
            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(
            id,
            resource_server_identifier=resource_server_identifier,
            permission_name=permission_name,
            from_=from_,
            take=take,
            request_options=request_options,
        )
