# 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.group import Group
from ...types.list_role_groups_response_content import ListRoleGroupsResponseContent
from .raw_client import AsyncRawGroupsClient, RawGroupsClient

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


class GroupsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawGroupsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawGroupsClient
        """
        return self._raw_client

    def get(
        self,
        id: str,
        *,
        from_: typing.Optional[str] = None,
        take: typing.Optional[int] = 50,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SyncPager[Group, ListRoleGroupsResponseContent]:
        """
        Lists the groups to which the specified role is assigned.

        Parameters
        ----------
        id : str
            Unique identifier for the role (service-generated).

        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[Group, ListRoleGroupsResponseContent]
            Role's groups successfully retrieved.

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

        client = Auth0(
            token="YOUR_TOKEN",
        )
        response = client.roles.groups.get(
            id="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.get(id, from_=from_, take=take, request_options=request_options)

    def create(
        self, id: str, *, groups: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Assign one or more groups to a specified role.

        Parameters
        ----------
        id : str
            Unique identifier for the role (service-generated).

        groups : typing.Sequence[str]
            Array of group IDs to assign to the role.

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

        Returns
        -------
        None

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

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

    def delete(
        self, id: str, *, groups: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Unassign one or more groups from a specified role.

        Parameters
        ----------
        id : str
            Unique identifier for the role (service-generated).

        groups : typing.Sequence[str]
            Array of group IDs to remove from the role.

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

        Returns
        -------
        None

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

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


class AsyncGroupsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawGroupsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawGroupsClient
        """
        return self._raw_client

    async def get(
        self,
        id: str,
        *,
        from_: typing.Optional[str] = None,
        take: typing.Optional[int] = 50,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncPager[Group, ListRoleGroupsResponseContent]:
        """
        Lists the groups to which the specified role is assigned.

        Parameters
        ----------
        id : str
            Unique identifier for the role (service-generated).

        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[Group, ListRoleGroupsResponseContent]
            Role's groups successfully retrieved.

        Examples
        --------
        import asyncio

        from auth0 import AsyncAuth0

        client = AsyncAuth0(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            response = await client.roles.groups.get(
                id="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.get(id, from_=from_, take=take, request_options=request_options)

    async def create(
        self, id: str, *, groups: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Assign one or more groups to a specified role.

        Parameters
        ----------
        id : str
            Unique identifier for the role (service-generated).

        groups : typing.Sequence[str]
            Array of group IDs to assign to the role.

        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.groups.create(
                id="id",
                groups=["groups"],
            )


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

    async def delete(
        self, id: str, *, groups: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Unassign one or more groups from a specified role.

        Parameters
        ----------
        id : str
            Unique identifier for the role (service-generated).

        groups : typing.Sequence[str]
            Array of group IDs to remove from the role.

        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.groups.delete(
                id="id",
                groups=["groups"],
            )


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