# 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.get_group_response_content import GetGroupResponseContent
from ..types.group import Group
from ..types.list_groups_paginated_response_content import ListGroupsPaginatedResponseContent
from .raw_client import AsyncRawGroupsClient, RawGroupsClient

if typing.TYPE_CHECKING:
    from .members.client import AsyncMembersClient, MembersClient
    from .roles.client import AsyncRolesClient, RolesClient


class GroupsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawGroupsClient(client_wrapper=client_wrapper)
        self._client_wrapper = client_wrapper
        self._members: typing.Optional[MembersClient] = None
        self._roles: typing.Optional[RolesClient] = None

    @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 list(
        self,
        *,
        connection_id: typing.Optional[str] = None,
        name: typing.Optional[str] = None,
        external_id: typing.Optional[str] = None,
        search: typing.Optional[str] = None,
        fields: typing.Optional[str] = None,
        include_fields: typing.Optional[bool] = None,
        from_: typing.Optional[str] = None,
        take: typing.Optional[int] = 50,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SyncPager[Group, ListGroupsPaginatedResponseContent]:
        """
        List all groups in your tenant.

        Parameters
        ----------
        connection_id : typing.Optional[str]
            Filter groups by connection ID.

        name : typing.Optional[str]
            Filter groups by name.

        external_id : typing.Optional[str]
            Filter groups by external ID.

        search : typing.Optional[str]
            Search for groups by name or external ID.

        fields : typing.Optional[str]
            A comma separated list of fields to include or exclude (depending on include_fields) from the result, empty to retrieve all fields

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

        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, ListGroupsPaginatedResponseContent]
            Groups successfully retrieved.

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

        client = Auth0(
            token="YOUR_TOKEN",
        )
        response = client.groups.list(
            connection_id="connection_id",
            name="name",
            external_id="external_id",
            search="search",
            fields="fields",
            include_fields=True,
            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(
            connection_id=connection_id,
            name=name,
            external_id=external_id,
            search=search,
            fields=fields,
            include_fields=include_fields,
            from_=from_,
            take=take,
            request_options=request_options,
        )

    def get(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> GetGroupResponseContent:
        """
        Retrieve a group by its ID.

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

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

        Returns
        -------
        GetGroupResponseContent
            Group successfully retrieved.

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

        client = Auth0(
            token="YOUR_TOKEN",
        )
        client.groups.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 group by its ID.

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

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

        Returns
        -------
        None

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

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

    @property
    def members(self):
        if self._members is None:
            from .members.client import MembersClient  # noqa: E402

            self._members = MembersClient(client_wrapper=self._client_wrapper)
        return self._members

    @property
    def roles(self):
        if self._roles is None:
            from .roles.client import RolesClient  # noqa: E402

            self._roles = RolesClient(client_wrapper=self._client_wrapper)
        return self._roles


class AsyncGroupsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawGroupsClient(client_wrapper=client_wrapper)
        self._client_wrapper = client_wrapper
        self._members: typing.Optional[AsyncMembersClient] = None
        self._roles: typing.Optional[AsyncRolesClient] = None

    @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 list(
        self,
        *,
        connection_id: typing.Optional[str] = None,
        name: typing.Optional[str] = None,
        external_id: typing.Optional[str] = None,
        search: typing.Optional[str] = None,
        fields: typing.Optional[str] = None,
        include_fields: typing.Optional[bool] = None,
        from_: typing.Optional[str] = None,
        take: typing.Optional[int] = 50,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncPager[Group, ListGroupsPaginatedResponseContent]:
        """
        List all groups in your tenant.

        Parameters
        ----------
        connection_id : typing.Optional[str]
            Filter groups by connection ID.

        name : typing.Optional[str]
            Filter groups by name.

        external_id : typing.Optional[str]
            Filter groups by external ID.

        search : typing.Optional[str]
            Search for groups by name or external ID.

        fields : typing.Optional[str]
            A comma separated list of fields to include or exclude (depending on include_fields) from the result, empty to retrieve all fields

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

        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, ListGroupsPaginatedResponseContent]
            Groups successfully retrieved.

        Examples
        --------
        import asyncio

        from auth0 import AsyncAuth0

        client = AsyncAuth0(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            response = await client.groups.list(
                connection_id="connection_id",
                name="name",
                external_id="external_id",
                search="search",
                fields="fields",
                include_fields=True,
                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(
            connection_id=connection_id,
            name=name,
            external_id=external_id,
            search=search,
            fields=fields,
            include_fields=include_fields,
            from_=from_,
            take=take,
            request_options=request_options,
        )

    async def get(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> GetGroupResponseContent:
        """
        Retrieve a group by its ID.

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

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

        Returns
        -------
        GetGroupResponseContent
            Group successfully retrieved.

        Examples
        --------
        import asyncio

        from auth0 import AsyncAuth0

        client = AsyncAuth0(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.groups.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 group by its ID.

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

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


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

    @property
    def members(self):
        if self._members is None:
            from .members.client import AsyncMembersClient  # noqa: E402

            self._members = AsyncMembersClient(client_wrapper=self._client_wrapper)
        return self._members

    @property
    def roles(self):
        if self._roles is None:
            from .roles.client import AsyncRolesClient  # noqa: E402

            self._roles = AsyncRolesClient(client_wrapper=self._client_wrapper)
        return self._roles
