# 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_organization_group_roles_response_content import ListOrganizationGroupRolesResponseContent
from ....types.role import Role
from .raw_client import AsyncRawRolesClient, RawRolesClient

# 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)

    @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,
        organization_id: str,
        group_id: str,
        *,
        from_: typing.Optional[str] = None,
        take: typing.Optional[int] = 50,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SyncPager[Role, ListOrganizationGroupRolesResponseContent]:
        """
        Lists the roles assigned to the specified group in the context of an organization.

        Parameters
        ----------
        organization_id : str
            ID of the organization

        group_id : str
            ID of the group

        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[Role, ListOrganizationGroupRolesResponseContent]
            Organization group roles successfully retrieved.

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

        client = Auth0(
            token="YOUR_TOKEN",
        )
        response = client.organizations.groups.roles.list(
            organization_id="organization_id",
            group_id="group_id",
            from_="from",
            take=1,
        )
        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(organization_id, group_id, from_=from_, take=take, request_options=request_options)

    def create(
        self,
        organization_id: str,
        group_id: str,
        *,
        roles: typing.Sequence[str],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Assign one or more roles to a specified group in the context of an organization.

        Parameters
        ----------
        organization_id : str
            ID of the organization

        group_id : str
            ID of the group

        roles : typing.Sequence[str]
            Array of role IDs to assign to organization group.

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

        Returns
        -------
        None

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

        client = Auth0(
            token="YOUR_TOKEN",
        )
        client.organizations.groups.roles.create(
            organization_id="organization_id",
            group_id="group_id",
            roles=["roles"],
        )
        """
        _response = self._raw_client.create(organization_id, group_id, roles=roles, request_options=request_options)
        return _response.data

    def delete(
        self,
        organization_id: str,
        group_id: str,
        *,
        roles: typing.Sequence[str],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Unassign one or more roles from a specified group in the context of an organization.

        Parameters
        ----------
        organization_id : str
            ID of the organization

        group_id : str
            ID of the group

        roles : typing.Sequence[str]
            Array of role IDs to delete from organization group.

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

        Returns
        -------
        None

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

        client = Auth0(
            token="YOUR_TOKEN",
        )
        client.organizations.groups.roles.delete(
            organization_id="organization_id",
            group_id="group_id",
            roles=["roles"],
        )
        """
        _response = self._raw_client.delete(organization_id, group_id, roles=roles, request_options=request_options)
        return _response.data


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,
        organization_id: str,
        group_id: str,
        *,
        from_: typing.Optional[str] = None,
        take: typing.Optional[int] = 50,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncPager[Role, ListOrganizationGroupRolesResponseContent]:
        """
        Lists the roles assigned to the specified group in the context of an organization.

        Parameters
        ----------
        organization_id : str
            ID of the organization

        group_id : str
            ID of the group

        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[Role, ListOrganizationGroupRolesResponseContent]
            Organization group roles successfully retrieved.

        Examples
        --------
        import asyncio

        from auth0 import AsyncAuth0

        client = AsyncAuth0(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            response = await client.organizations.groups.roles.list(
                organization_id="organization_id",
                group_id="group_id",
                from_="from",
                take=1,
            )
            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(
            organization_id, group_id, from_=from_, take=take, request_options=request_options
        )

    async def create(
        self,
        organization_id: str,
        group_id: str,
        *,
        roles: typing.Sequence[str],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Assign one or more roles to a specified group in the context of an organization.

        Parameters
        ----------
        organization_id : str
            ID of the organization

        group_id : str
            ID of the group

        roles : typing.Sequence[str]
            Array of role IDs to assign to organization group.

        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.organizations.groups.roles.create(
                organization_id="organization_id",
                group_id="group_id",
                roles=["roles"],
            )


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

    async def delete(
        self,
        organization_id: str,
        group_id: str,
        *,
        roles: typing.Sequence[str],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Unassign one or more roles from a specified group in the context of an organization.

        Parameters
        ----------
        organization_id : str
            ID of the organization

        group_id : str
            ID of the group

        roles : typing.Sequence[str]
            Array of role IDs to delete from organization group.

        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.organizations.groups.roles.delete(
                organization_id="organization_id",
                group_id="group_id",
                roles=["roles"],
            )


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