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

import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.entitlement_trigger_config import EntitlementTriggerConfig
from .raw_client import AsyncRawWebhooksClient, RawWebhooksClient
from .types.count_webhook_events_response import CountWebhookEventsResponse
from .types.count_webhooks_response import CountWebhooksResponse
from .types.create_webhook_request_body_request_types_item import CreateWebhookRequestBodyRequestTypesItem
from .types.create_webhook_response import CreateWebhookResponse
from .types.delete_webhook_response import DeleteWebhookResponse
from .types.get_webhook_event_response import GetWebhookEventResponse
from .types.get_webhook_response import GetWebhookResponse
from .types.list_webhook_events_response import ListWebhookEventsResponse
from .types.list_webhooks_response import ListWebhooksResponse
from .types.update_webhook_request_body_request_types_item import UpdateWebhookRequestBodyRequestTypesItem
from .types.update_webhook_request_body_status import UpdateWebhookRequestBodyStatus
from .types.update_webhook_response import UpdateWebhookResponse

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


class WebhooksClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawWebhooksClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawWebhooksClient
        """
        return self._raw_client

    def list_webhook_events(
        self,
        *,
        ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        q: typing.Optional[str] = None,
        webhook_id: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListWebhookEventsResponse:
        """
        Parameters
        ----------
        ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]

        q : typing.Optional[str]

        webhook_id : typing.Optional[str]

        limit : typing.Optional[int]
            Page limit (default 100)

        offset : typing.Optional[int]
            Page offset (default 0)

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

        Returns
        -------
        ListWebhookEventsResponse
            OK

        Examples
        --------
        from schematic import Schematic

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.webhooks.list_webhook_events()
        """
        _response = self._raw_client.list_webhook_events(
            ids=ids, q=q, webhook_id=webhook_id, limit=limit, offset=offset, request_options=request_options
        )
        return _response.data

    def get_webhook_event(
        self, webhook_event_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> GetWebhookEventResponse:
        """
        Parameters
        ----------
        webhook_event_id : str
            webhook_event_id

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

        Returns
        -------
        GetWebhookEventResponse
            OK

        Examples
        --------
        from schematic import Schematic

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.webhooks.get_webhook_event(
            webhook_event_id="webhook_event_id",
        )
        """
        _response = self._raw_client.get_webhook_event(webhook_event_id, request_options=request_options)
        return _response.data

    def count_webhook_events(
        self,
        *,
        ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        q: typing.Optional[str] = None,
        webhook_id: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CountWebhookEventsResponse:
        """
        Parameters
        ----------
        ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]

        q : typing.Optional[str]

        webhook_id : typing.Optional[str]

        limit : typing.Optional[int]
            Page limit (default 100)

        offset : typing.Optional[int]
            Page offset (default 0)

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

        Returns
        -------
        CountWebhookEventsResponse
            OK

        Examples
        --------
        from schematic import Schematic

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.webhooks.count_webhook_events()
        """
        _response = self._raw_client.count_webhook_events(
            ids=ids, q=q, webhook_id=webhook_id, limit=limit, offset=offset, request_options=request_options
        )
        return _response.data

    def list_webhooks(
        self,
        *,
        q: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListWebhooksResponse:
        """
        Parameters
        ----------
        q : typing.Optional[str]

        limit : typing.Optional[int]
            Page limit (default 100)

        offset : typing.Optional[int]
            Page offset (default 0)

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

        Returns
        -------
        ListWebhooksResponse
            OK

        Examples
        --------
        from schematic import Schematic

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.webhooks.list_webhooks()
        """
        _response = self._raw_client.list_webhooks(q=q, limit=limit, offset=offset, request_options=request_options)
        return _response.data

    def create_webhook(
        self,
        *,
        name: str,
        request_types: typing.Sequence[CreateWebhookRequestBodyRequestTypesItem],
        url: str,
        entitlement_trigger_configs: typing.Optional[typing.Sequence[EntitlementTriggerConfig]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateWebhookResponse:
        """
        Parameters
        ----------
        name : str

        request_types : typing.Sequence[CreateWebhookRequestBodyRequestTypesItem]

        url : str

        entitlement_trigger_configs : typing.Optional[typing.Sequence[EntitlementTriggerConfig]]

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

        Returns
        -------
        CreateWebhookResponse
            Created

        Examples
        --------
        from schematic import Schematic

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.webhooks.create_webhook(
            name="name",
            request_types=["company.updated"],
            url="url",
        )
        """
        _response = self._raw_client.create_webhook(
            name=name,
            request_types=request_types,
            url=url,
            entitlement_trigger_configs=entitlement_trigger_configs,
            request_options=request_options,
        )
        return _response.data

    def get_webhook(
        self, webhook_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> GetWebhookResponse:
        """
        Parameters
        ----------
        webhook_id : str
            webhook_id

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

        Returns
        -------
        GetWebhookResponse
            OK

        Examples
        --------
        from schematic import Schematic

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.webhooks.get_webhook(
            webhook_id="webhook_id",
        )
        """
        _response = self._raw_client.get_webhook(webhook_id, request_options=request_options)
        return _response.data

    def update_webhook(
        self,
        webhook_id: str,
        *,
        entitlement_trigger_configs: typing.Optional[typing.Sequence[EntitlementTriggerConfig]] = OMIT,
        name: typing.Optional[str] = OMIT,
        request_types: typing.Optional[typing.Sequence[UpdateWebhookRequestBodyRequestTypesItem]] = OMIT,
        status: typing.Optional[UpdateWebhookRequestBodyStatus] = OMIT,
        url: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpdateWebhookResponse:
        """
        Parameters
        ----------
        webhook_id : str
            webhook_id

        entitlement_trigger_configs : typing.Optional[typing.Sequence[EntitlementTriggerConfig]]

        name : typing.Optional[str]

        request_types : typing.Optional[typing.Sequence[UpdateWebhookRequestBodyRequestTypesItem]]

        status : typing.Optional[UpdateWebhookRequestBodyStatus]

        url : typing.Optional[str]

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

        Returns
        -------
        UpdateWebhookResponse
            OK

        Examples
        --------
        from schematic import Schematic

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.webhooks.update_webhook(
            webhook_id="webhook_id",
        )
        """
        _response = self._raw_client.update_webhook(
            webhook_id,
            entitlement_trigger_configs=entitlement_trigger_configs,
            name=name,
            request_types=request_types,
            status=status,
            url=url,
            request_options=request_options,
        )
        return _response.data

    def delete_webhook(
        self, webhook_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DeleteWebhookResponse:
        """
        Parameters
        ----------
        webhook_id : str
            webhook_id

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

        Returns
        -------
        DeleteWebhookResponse
            OK

        Examples
        --------
        from schematic import Schematic

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.webhooks.delete_webhook(
            webhook_id="webhook_id",
        )
        """
        _response = self._raw_client.delete_webhook(webhook_id, request_options=request_options)
        return _response.data

    def count_webhooks(
        self,
        *,
        q: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CountWebhooksResponse:
        """
        Parameters
        ----------
        q : typing.Optional[str]

        limit : typing.Optional[int]
            Page limit (default 100)

        offset : typing.Optional[int]
            Page offset (default 0)

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

        Returns
        -------
        CountWebhooksResponse
            OK

        Examples
        --------
        from schematic import Schematic

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.webhooks.count_webhooks()
        """
        _response = self._raw_client.count_webhooks(q=q, limit=limit, offset=offset, request_options=request_options)
        return _response.data


class AsyncWebhooksClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawWebhooksClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawWebhooksClient
        """
        return self._raw_client

    async def list_webhook_events(
        self,
        *,
        ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        q: typing.Optional[str] = None,
        webhook_id: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListWebhookEventsResponse:
        """
        Parameters
        ----------
        ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]

        q : typing.Optional[str]

        webhook_id : typing.Optional[str]

        limit : typing.Optional[int]
            Page limit (default 100)

        offset : typing.Optional[int]
            Page offset (default 0)

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

        Returns
        -------
        ListWebhookEventsResponse
            OK

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.webhooks.list_webhook_events()


        asyncio.run(main())
        """
        _response = await self._raw_client.list_webhook_events(
            ids=ids, q=q, webhook_id=webhook_id, limit=limit, offset=offset, request_options=request_options
        )
        return _response.data

    async def get_webhook_event(
        self, webhook_event_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> GetWebhookEventResponse:
        """
        Parameters
        ----------
        webhook_event_id : str
            webhook_event_id

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

        Returns
        -------
        GetWebhookEventResponse
            OK

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.webhooks.get_webhook_event(
                webhook_event_id="webhook_event_id",
            )


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

    async def count_webhook_events(
        self,
        *,
        ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        q: typing.Optional[str] = None,
        webhook_id: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CountWebhookEventsResponse:
        """
        Parameters
        ----------
        ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]

        q : typing.Optional[str]

        webhook_id : typing.Optional[str]

        limit : typing.Optional[int]
            Page limit (default 100)

        offset : typing.Optional[int]
            Page offset (default 0)

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

        Returns
        -------
        CountWebhookEventsResponse
            OK

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.webhooks.count_webhook_events()


        asyncio.run(main())
        """
        _response = await self._raw_client.count_webhook_events(
            ids=ids, q=q, webhook_id=webhook_id, limit=limit, offset=offset, request_options=request_options
        )
        return _response.data

    async def list_webhooks(
        self,
        *,
        q: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListWebhooksResponse:
        """
        Parameters
        ----------
        q : typing.Optional[str]

        limit : typing.Optional[int]
            Page limit (default 100)

        offset : typing.Optional[int]
            Page offset (default 0)

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

        Returns
        -------
        ListWebhooksResponse
            OK

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.webhooks.list_webhooks()


        asyncio.run(main())
        """
        _response = await self._raw_client.list_webhooks(
            q=q, limit=limit, offset=offset, request_options=request_options
        )
        return _response.data

    async def create_webhook(
        self,
        *,
        name: str,
        request_types: typing.Sequence[CreateWebhookRequestBodyRequestTypesItem],
        url: str,
        entitlement_trigger_configs: typing.Optional[typing.Sequence[EntitlementTriggerConfig]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateWebhookResponse:
        """
        Parameters
        ----------
        name : str

        request_types : typing.Sequence[CreateWebhookRequestBodyRequestTypesItem]

        url : str

        entitlement_trigger_configs : typing.Optional[typing.Sequence[EntitlementTriggerConfig]]

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

        Returns
        -------
        CreateWebhookResponse
            Created

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.webhooks.create_webhook(
                name="name",
                request_types=["company.updated"],
                url="url",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_webhook(
            name=name,
            request_types=request_types,
            url=url,
            entitlement_trigger_configs=entitlement_trigger_configs,
            request_options=request_options,
        )
        return _response.data

    async def get_webhook(
        self, webhook_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> GetWebhookResponse:
        """
        Parameters
        ----------
        webhook_id : str
            webhook_id

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

        Returns
        -------
        GetWebhookResponse
            OK

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.webhooks.get_webhook(
                webhook_id="webhook_id",
            )


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

    async def update_webhook(
        self,
        webhook_id: str,
        *,
        entitlement_trigger_configs: typing.Optional[typing.Sequence[EntitlementTriggerConfig]] = OMIT,
        name: typing.Optional[str] = OMIT,
        request_types: typing.Optional[typing.Sequence[UpdateWebhookRequestBodyRequestTypesItem]] = OMIT,
        status: typing.Optional[UpdateWebhookRequestBodyStatus] = OMIT,
        url: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpdateWebhookResponse:
        """
        Parameters
        ----------
        webhook_id : str
            webhook_id

        entitlement_trigger_configs : typing.Optional[typing.Sequence[EntitlementTriggerConfig]]

        name : typing.Optional[str]

        request_types : typing.Optional[typing.Sequence[UpdateWebhookRequestBodyRequestTypesItem]]

        status : typing.Optional[UpdateWebhookRequestBodyStatus]

        url : typing.Optional[str]

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

        Returns
        -------
        UpdateWebhookResponse
            OK

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.webhooks.update_webhook(
                webhook_id="webhook_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_webhook(
            webhook_id,
            entitlement_trigger_configs=entitlement_trigger_configs,
            name=name,
            request_types=request_types,
            status=status,
            url=url,
            request_options=request_options,
        )
        return _response.data

    async def delete_webhook(
        self, webhook_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DeleteWebhookResponse:
        """
        Parameters
        ----------
        webhook_id : str
            webhook_id

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

        Returns
        -------
        DeleteWebhookResponse
            OK

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.webhooks.delete_webhook(
                webhook_id="webhook_id",
            )


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

    async def count_webhooks(
        self,
        *,
        q: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CountWebhooksResponse:
        """
        Parameters
        ----------
        q : typing.Optional[str]

        limit : typing.Optional[int]
            Page limit (default 100)

        offset : typing.Optional[int]
            Page offset (default 0)

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

        Returns
        -------
        CountWebhooksResponse
            OK

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.webhooks.count_webhooks()


        asyncio.run(main())
        """
        _response = await self._raw_client.count_webhooks(
            q=q, limit=limit, offset=offset, request_options=request_options
        )
        return _response.data
