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

from __future__ import annotations

import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.pagination import AsyncPager, SyncPager
from ..core.request_options import RequestOptions
from ..types.create_role_response_content import CreateRoleResponseContent
from ..types.get_role_response_content import GetRoleResponseContent
from ..types.list_roles_offset_paginated_response_content import ListRolesOffsetPaginatedResponseContent
from ..types.role import Role
from ..types.update_role_response_content import UpdateRoleResponseContent
from .raw_client import AsyncRawRolesClient, RawRolesClient

if typing.TYPE_CHECKING:
    from .groups.client import AsyncGroupsClient, GroupsClient
    from .permissions.client import AsyncPermissionsClient, PermissionsClient
    from .users.client import AsyncUsersClient, UsersClient
# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class RolesClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawRolesClient(client_wrapper=client_wrapper)
        self._client_wrapper = client_wrapper
        self._groups: typing.Optional[GroupsClient] = None
        self._permissions: typing.Optional[PermissionsClient] = None
        self._users: typing.Optional[UsersClient] = None

    @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,
        *,
        per_page: typing.Optional[int] = 50,
        page: typing.Optional[int] = 0,
        include_totals: typing.Optional[bool] = True,
        name_filter: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SyncPager[Role, ListRolesOffsetPaginatedResponseContent]:
        """
        Retrieve detailed list of user roles created in your tenant.

        **Note**: The returned list does not include standard roles available for tenant members, such as Admin or Support Access.

        Parameters
        ----------
        per_page : typing.Optional[int]
            Number of results per page. Defaults to 50.

        page : typing.Optional[int]
            Page index of the results to return. First page is 0.

        include_totals : typing.Optional[bool]
            Return results inside an object that contains the total result count (true) or as a direct array of results (false, default).

        name_filter : typing.Optional[str]
            Optional filter on name (case-insensitive).

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

        Returns
        -------
        SyncPager[Role, ListRolesOffsetPaginatedResponseContent]
            Roles successfully retrieved.

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

        client = Auth0(
            token="YOUR_TOKEN",
        )
        response = client.roles.list(
            per_page=1,
            page=1,
            include_totals=True,
            name_filter="name_filter",
        )
        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(
            per_page=per_page,
            page=page,
            include_totals=include_totals,
            name_filter=name_filter,
            request_options=request_options,
        )

    def create(
        self,
        *,
        name: str,
        description: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateRoleResponseContent:
        """
        Create a user role for [Role-Based Access Control](https://auth0.com/docs/manage-users/access-control/rbac).

        **Note**: New roles are not associated with any permissions by default. To assign existing permissions to your role, review Associate Permissions with a Role. To create new permissions, review Add API Permissions.

        Parameters
        ----------
        name : str
            Name of the role.

        description : typing.Optional[str]
            Description of the role.

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

        Returns
        -------
        CreateRoleResponseContent
            Role successfully created.

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

        client = Auth0(
            token="YOUR_TOKEN",
        )
        client.roles.create(
            name="name",
        )
        """
        _response = self._raw_client.create(name=name, description=description, request_options=request_options)
        return _response.data

    def get(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> GetRoleResponseContent:
        """
        Retrieve details about a specific [user role](https://auth0.com/docs/manage-users/access-control/rbac) specified by ID.

        Parameters
        ----------
        id : str
            ID of the role to retrieve.

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

        Returns
        -------
        GetRoleResponseContent
            Role successfully retrieved.

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

        client = Auth0(
            token="YOUR_TOKEN",
        )
        client.roles.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 specific [user role](https://auth0.com/docs/manage-users/access-control/rbac) from your tenant. Once deleted, it is removed from any user who was previously assigned that role. This action cannot be undone.

        Parameters
        ----------
        id : str
            ID of the role to delete.

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

        Returns
        -------
        None

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

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

    def update(
        self,
        id: str,
        *,
        name: typing.Optional[str] = OMIT,
        description: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpdateRoleResponseContent:
        """
        Modify the details of a specific [user role](https://auth0.com/docs/manage-users/access-control/rbac) specified by ID.

        Parameters
        ----------
        id : str
            ID of the role to update.

        name : typing.Optional[str]
            Name of this role.

        description : typing.Optional[str]
            Description of this role.

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

        Returns
        -------
        UpdateRoleResponseContent
            Role successfully updated.

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

        client = Auth0(
            token="YOUR_TOKEN",
        )
        client.roles.update(
            id="id",
        )
        """
        _response = self._raw_client.update(id, name=name, description=description, request_options=request_options)
        return _response.data

    @property
    def groups(self):
        if self._groups is None:
            from .groups.client import GroupsClient  # noqa: E402

            self._groups = GroupsClient(client_wrapper=self._client_wrapper)
        return self._groups

    @property
    def permissions(self):
        if self._permissions is None:
            from .permissions.client import PermissionsClient  # noqa: E402

            self._permissions = PermissionsClient(client_wrapper=self._client_wrapper)
        return self._permissions

    @property
    def users(self):
        if self._users is None:
            from .users.client import UsersClient  # noqa: E402

            self._users = UsersClient(client_wrapper=self._client_wrapper)
        return self._users


class AsyncRolesClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawRolesClient(client_wrapper=client_wrapper)
        self._client_wrapper = client_wrapper
        self._groups: typing.Optional[AsyncGroupsClient] = None
        self._permissions: typing.Optional[AsyncPermissionsClient] = None
        self._users: typing.Optional[AsyncUsersClient] = None

    @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,
        *,
        per_page: typing.Optional[int] = 50,
        page: typing.Optional[int] = 0,
        include_totals: typing.Optional[bool] = True,
        name_filter: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncPager[Role, ListRolesOffsetPaginatedResponseContent]:
        """
        Retrieve detailed list of user roles created in your tenant.

        **Note**: The returned list does not include standard roles available for tenant members, such as Admin or Support Access.

        Parameters
        ----------
        per_page : typing.Optional[int]
            Number of results per page. Defaults to 50.

        page : typing.Optional[int]
            Page index of the results to return. First page is 0.

        include_totals : typing.Optional[bool]
            Return results inside an object that contains the total result count (true) or as a direct array of results (false, default).

        name_filter : typing.Optional[str]
            Optional filter on name (case-insensitive).

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

        Returns
        -------
        AsyncPager[Role, ListRolesOffsetPaginatedResponseContent]
            Roles successfully retrieved.

        Examples
        --------
        import asyncio

        from auth0 import AsyncAuth0

        client = AsyncAuth0(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            response = await client.roles.list(
                per_page=1,
                page=1,
                include_totals=True,
                name_filter="name_filter",
            )
            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(
            per_page=per_page,
            page=page,
            include_totals=include_totals,
            name_filter=name_filter,
            request_options=request_options,
        )

    async def create(
        self,
        *,
        name: str,
        description: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateRoleResponseContent:
        """
        Create a user role for [Role-Based Access Control](https://auth0.com/docs/manage-users/access-control/rbac).

        **Note**: New roles are not associated with any permissions by default. To assign existing permissions to your role, review Associate Permissions with a Role. To create new permissions, review Add API Permissions.

        Parameters
        ----------
        name : str
            Name of the role.

        description : typing.Optional[str]
            Description of the role.

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

        Returns
        -------
        CreateRoleResponseContent
            Role successfully created.

        Examples
        --------
        import asyncio

        from auth0 import AsyncAuth0

        client = AsyncAuth0(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.roles.create(
                name="name",
            )


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

    async def get(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> GetRoleResponseContent:
        """
        Retrieve details about a specific [user role](https://auth0.com/docs/manage-users/access-control/rbac) specified by ID.

        Parameters
        ----------
        id : str
            ID of the role to retrieve.

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

        Returns
        -------
        GetRoleResponseContent
            Role successfully retrieved.

        Examples
        --------
        import asyncio

        from auth0 import AsyncAuth0

        client = AsyncAuth0(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.roles.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 specific [user role](https://auth0.com/docs/manage-users/access-control/rbac) from your tenant. Once deleted, it is removed from any user who was previously assigned that role. This action cannot be undone.

        Parameters
        ----------
        id : str
            ID of the role 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.roles.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,
        *,
        name: typing.Optional[str] = OMIT,
        description: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpdateRoleResponseContent:
        """
        Modify the details of a specific [user role](https://auth0.com/docs/manage-users/access-control/rbac) specified by ID.

        Parameters
        ----------
        id : str
            ID of the role to update.

        name : typing.Optional[str]
            Name of this role.

        description : typing.Optional[str]
            Description of this role.

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

        Returns
        -------
        UpdateRoleResponseContent
            Role successfully updated.

        Examples
        --------
        import asyncio

        from auth0 import AsyncAuth0

        client = AsyncAuth0(
            token="YOUR_TOKEN",
        )


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


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

    @property
    def groups(self):
        if self._groups is None:
            from .groups.client import AsyncGroupsClient  # noqa: E402

            self._groups = AsyncGroupsClient(client_wrapper=self._client_wrapper)
        return self._groups

    @property
    def permissions(self):
        if self._permissions is None:
            from .permissions.client import AsyncPermissionsClient  # noqa: E402

            self._permissions = AsyncPermissionsClient(client_wrapper=self._client_wrapper)
        return self._permissions

    @property
    def users(self):
        if self._users is None:
            from .users.client import AsyncUsersClient  # noqa: E402

            self._users = AsyncUsersClient(client_wrapper=self._client_wrapper)
        return self._users
