# 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.create_rate_limit_policy_response_content import CreateRateLimitPolicyResponseContent
from ..types.get_rate_limit_policy_response_content import GetRateLimitPolicyResponseContent
from ..types.list_rate_limit_policies_paginated_response_content import ListRateLimitPoliciesPaginatedResponseContent
from ..types.patch_rate_limit_policy_configuration_request_content import (
    PatchRateLimitPolicyConfigurationRequestContent,
)
from ..types.rate_limit_policy import RateLimitPolicy
from ..types.rate_limit_policy_configuration import RateLimitPolicyConfiguration
from ..types.rate_limit_policy_consumer_enum import RateLimitPolicyConsumerEnum
from ..types.rate_limit_policy_resource_enum import RateLimitPolicyResourceEnum
from ..types.update_rate_limit_policy_response_content import UpdateRateLimitPolicyResponseContent
from .raw_client import AsyncRawRateLimitPoliciesClient, RawRateLimitPoliciesClient

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


class RateLimitPoliciesClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawRateLimitPoliciesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawRateLimitPoliciesClient
        """
        return self._raw_client

    def list(
        self,
        *,
        resource: typing.Optional[RateLimitPolicyResourceEnum] = None,
        consumer: typing.Optional[RateLimitPolicyConsumerEnum] = None,
        consumer_selector: typing.Optional[str] = None,
        take: typing.Optional[int] = 50,
        from_: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SyncPager[RateLimitPolicy, ListRateLimitPoliciesPaginatedResponseContent]:
        """
        Parameters
        ----------
        resource : typing.Optional[RateLimitPolicyResourceEnum]
            The API protected by the Rate Limit Policy.

        consumer : typing.Optional[RateLimitPolicyConsumerEnum]
            The consumer to which the rate limit policy applies.

        consumer_selector : typing.Optional[str]
            Identifier or category within the consumer to which the policy applies. Supported values: `client_id:<client_id>` to target a specific client by ID, `client_id:<cimd_uri>` to target a CIMD client by URI, `cimd_clients` to target all CIMD clients, `third_party_clients` to target all third-party clients, or `default` to apply the policy to any consumer identifier not otherwise explicitly targeted.

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

        from_ : typing.Optional[str]
            Cursor for pagination.

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

        Returns
        -------
        SyncPager[RateLimitPolicy, ListRateLimitPoliciesPaginatedResponseContent]
            Rate limit policies retrieved successfully.

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

        client = Auth0(
            token="YOUR_TOKEN",
        )
        response = client.rate_limit_policies.list(
            resource="oauth_authentication_api",
            consumer="client",
            consumer_selector="consumer_selector",
            take=1,
            from_="from",
        )
        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(
            resource=resource,
            consumer=consumer,
            consumer_selector=consumer_selector,
            take=take,
            from_=from_,
            request_options=request_options,
        )

    def create(
        self,
        *,
        resource: RateLimitPolicyResourceEnum,
        consumer: RateLimitPolicyConsumerEnum,
        consumer_selector: str,
        configuration: RateLimitPolicyConfiguration,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateRateLimitPolicyResponseContent:
        """
        Parameters
        ----------
        resource : RateLimitPolicyResourceEnum

        consumer : RateLimitPolicyConsumerEnum

        consumer_selector : str
            Identifier or category within the consumer to which the policy applies. Supported values: `client_id:<client_id>` to target a specific client by ID, `client_id:<cimd_uri>` to target a CIMD client by URI, `cimd_clients` to target all CIMD clients, `third_party_clients` to target all third-party clients, or `default` to apply the policy to any consumer identifier not otherwise explicitly targeted.

        configuration : RateLimitPolicyConfiguration

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

        Returns
        -------
        CreateRateLimitPolicyResponseContent
            Rate limit policy successfully created.

        Examples
        --------
        from auth0 import Auth0, RateLimitPolicyConfigurationZero

        client = Auth0(
            token="YOUR_TOKEN",
        )
        client.rate_limit_policies.create(
            resource="oauth_authentication_api",
            consumer="client",
            consumer_selector="consumer_selector",
            configuration=RateLimitPolicyConfigurationZero(
                action="allow",
            ),
        )
        """
        _response = self._raw_client.create(
            resource=resource,
            consumer=consumer,
            consumer_selector=consumer_selector,
            configuration=configuration,
            request_options=request_options,
        )
        return _response.data

    def get(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> GetRateLimitPolicyResponseContent:
        """
        Parameters
        ----------
        id : str
            Unique identifier for the Rate Limit Policy.

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

        Returns
        -------
        GetRateLimitPolicyResponseContent
            Rate limit policy retrieved successfully.

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

        client = Auth0(
            token="YOUR_TOKEN",
        )
        client.rate_limit_policies.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:
        """
        Parameters
        ----------
        id : str
            Unique identifier for the Rate Limit Policy.

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

        Returns
        -------
        None

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

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

    def update(
        self,
        id: str,
        *,
        configuration: PatchRateLimitPolicyConfigurationRequestContent,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpdateRateLimitPolicyResponseContent:
        """
        Parameters
        ----------
        id : str
            Unique identifier for the Rate Limit Policy.

        configuration : PatchRateLimitPolicyConfigurationRequestContent

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

        Returns
        -------
        UpdateRateLimitPolicyResponseContent
            Rate limit policy successfully updated.

        Examples
        --------
        from auth0 import Auth0, PatchRateLimitPolicyConfigurationRequestContentZero

        client = Auth0(
            token="YOUR_TOKEN",
        )
        client.rate_limit_policies.update(
            id="id",
            configuration=PatchRateLimitPolicyConfigurationRequestContentZero(
                action="allow",
            ),
        )
        """
        _response = self._raw_client.update(id, configuration=configuration, request_options=request_options)
        return _response.data


class AsyncRateLimitPoliciesClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawRateLimitPoliciesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawRateLimitPoliciesClient
        """
        return self._raw_client

    async def list(
        self,
        *,
        resource: typing.Optional[RateLimitPolicyResourceEnum] = None,
        consumer: typing.Optional[RateLimitPolicyConsumerEnum] = None,
        consumer_selector: typing.Optional[str] = None,
        take: typing.Optional[int] = 50,
        from_: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncPager[RateLimitPolicy, ListRateLimitPoliciesPaginatedResponseContent]:
        """
        Parameters
        ----------
        resource : typing.Optional[RateLimitPolicyResourceEnum]
            The API protected by the Rate Limit Policy.

        consumer : typing.Optional[RateLimitPolicyConsumerEnum]
            The consumer to which the rate limit policy applies.

        consumer_selector : typing.Optional[str]
            Identifier or category within the consumer to which the policy applies. Supported values: `client_id:<client_id>` to target a specific client by ID, `client_id:<cimd_uri>` to target a CIMD client by URI, `cimd_clients` to target all CIMD clients, `third_party_clients` to target all third-party clients, or `default` to apply the policy to any consumer identifier not otherwise explicitly targeted.

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

        from_ : typing.Optional[str]
            Cursor for pagination.

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

        Returns
        -------
        AsyncPager[RateLimitPolicy, ListRateLimitPoliciesPaginatedResponseContent]
            Rate limit policies retrieved successfully.

        Examples
        --------
        import asyncio

        from auth0 import AsyncAuth0

        client = AsyncAuth0(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            response = await client.rate_limit_policies.list(
                resource="oauth_authentication_api",
                consumer="client",
                consumer_selector="consumer_selector",
                take=1,
                from_="from",
            )
            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(
            resource=resource,
            consumer=consumer,
            consumer_selector=consumer_selector,
            take=take,
            from_=from_,
            request_options=request_options,
        )

    async def create(
        self,
        *,
        resource: RateLimitPolicyResourceEnum,
        consumer: RateLimitPolicyConsumerEnum,
        consumer_selector: str,
        configuration: RateLimitPolicyConfiguration,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateRateLimitPolicyResponseContent:
        """
        Parameters
        ----------
        resource : RateLimitPolicyResourceEnum

        consumer : RateLimitPolicyConsumerEnum

        consumer_selector : str
            Identifier or category within the consumer to which the policy applies. Supported values: `client_id:<client_id>` to target a specific client by ID, `client_id:<cimd_uri>` to target a CIMD client by URI, `cimd_clients` to target all CIMD clients, `third_party_clients` to target all third-party clients, or `default` to apply the policy to any consumer identifier not otherwise explicitly targeted.

        configuration : RateLimitPolicyConfiguration

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

        Returns
        -------
        CreateRateLimitPolicyResponseContent
            Rate limit policy successfully created.

        Examples
        --------
        import asyncio

        from auth0 import AsyncAuth0, RateLimitPolicyConfigurationZero

        client = AsyncAuth0(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.rate_limit_policies.create(
                resource="oauth_authentication_api",
                consumer="client",
                consumer_selector="consumer_selector",
                configuration=RateLimitPolicyConfigurationZero(
                    action="allow",
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(
            resource=resource,
            consumer=consumer,
            consumer_selector=consumer_selector,
            configuration=configuration,
            request_options=request_options,
        )
        return _response.data

    async def get(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> GetRateLimitPolicyResponseContent:
        """
        Parameters
        ----------
        id : str
            Unique identifier for the Rate Limit Policy.

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

        Returns
        -------
        GetRateLimitPolicyResponseContent
            Rate limit policy retrieved successfully.

        Examples
        --------
        import asyncio

        from auth0 import AsyncAuth0

        client = AsyncAuth0(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.rate_limit_policies.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:
        """
        Parameters
        ----------
        id : str
            Unique identifier for the Rate Limit Policy.

        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.rate_limit_policies.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,
        *,
        configuration: PatchRateLimitPolicyConfigurationRequestContent,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpdateRateLimitPolicyResponseContent:
        """
        Parameters
        ----------
        id : str
            Unique identifier for the Rate Limit Policy.

        configuration : PatchRateLimitPolicyConfigurationRequestContent

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

        Returns
        -------
        UpdateRateLimitPolicyResponseContent
            Rate limit policy successfully updated.

        Examples
        --------
        import asyncio

        from auth0 import (
            AsyncAuth0,
            PatchRateLimitPolicyConfigurationRequestContentZero,
        )

        client = AsyncAuth0(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.rate_limit_policies.update(
                id="id",
                configuration=PatchRateLimitPolicyConfigurationRequestContentZero(
                    action="allow",
                ),
            )


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