# 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 .raw_client import AsyncRawWebhooksClient, RawWebhooksClient
from .types.delete_webhook_id_response import DeleteWebhookIdResponse
from .types.get_webhook_response import GetWebhookResponse
from .types.post_webhook_request_events_item import PostWebhookRequestEventsItem
from .types.post_webhook_response import PostWebhookResponse

# 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 get_webhooks(
        self, *, webhook_id: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> GetWebhookResponse:
        """
        Retrieve all webhooks for the organization or a specific webhook by ID

        Parameters
        ----------
        webhook_id : typing.Optional[str]

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

        Returns
        -------
        GetWebhookResponse
            Successful response

        Examples
        --------
        from smallestai import SmallestAI

        client = SmallestAI(
            token="YOUR_TOKEN",
        )
        client.atoms.webhooks.get_webhooks()
        """
        _response = self._raw_client.get_webhooks(webhook_id=webhook_id, request_options=request_options)
        return _response.data

    def create_a_webhook(
        self,
        *,
        endpoint: str,
        description: str,
        events: typing.Sequence[PostWebhookRequestEventsItem],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> PostWebhookResponse:
        """
        Create a new webhook with subscriptions for specific agents and events

        Parameters
        ----------
        endpoint : str
            The webhook endpoint URL

        description : str
            The description of the webhook

        events : typing.Sequence[PostWebhookRequestEventsItem]
            Array of events to subscribe to

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

        Returns
        -------
        PostWebhookResponse
            Webhook created successfully

        Examples
        --------
        from smallestai import SmallestAI
        from smallestai.atoms.webhooks import PostWebhookRequestEventsItem

        client = SmallestAI(
            token="YOUR_TOKEN",
        )
        client.atoms.webhooks.create_a_webhook(
            endpoint="https://example.com/webhook",
            description="Webhook for conversation events",
            events=[PostWebhookRequestEventsItem()],
        )
        """
        _response = self._raw_client.create_a_webhook(
            endpoint=endpoint, description=description, events=events, request_options=request_options
        )
        return _response.data

    def delete_a_webhook(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DeleteWebhookIdResponse:
        """
        Delete a webhook by its ID

        Parameters
        ----------
        id : str
            The ID of the webhook to delete

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

        Returns
        -------
        DeleteWebhookIdResponse
            Webhook deleted successfully

        Examples
        --------
        from smallestai import SmallestAI

        client = SmallestAI(
            token="YOUR_TOKEN",
        )
        client.atoms.webhooks.delete_a_webhook(
            id="id",
        )
        """
        _response = self._raw_client.delete_a_webhook(id, 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 get_webhooks(
        self, *, webhook_id: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> GetWebhookResponse:
        """
        Retrieve all webhooks for the organization or a specific webhook by ID

        Parameters
        ----------
        webhook_id : typing.Optional[str]

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

        Returns
        -------
        GetWebhookResponse
            Successful response

        Examples
        --------
        import asyncio

        from smallestai import AsyncSmallestAI

        client = AsyncSmallestAI(
            token="YOUR_TOKEN",
        )


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


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

    async def create_a_webhook(
        self,
        *,
        endpoint: str,
        description: str,
        events: typing.Sequence[PostWebhookRequestEventsItem],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> PostWebhookResponse:
        """
        Create a new webhook with subscriptions for specific agents and events

        Parameters
        ----------
        endpoint : str
            The webhook endpoint URL

        description : str
            The description of the webhook

        events : typing.Sequence[PostWebhookRequestEventsItem]
            Array of events to subscribe to

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

        Returns
        -------
        PostWebhookResponse
            Webhook created successfully

        Examples
        --------
        import asyncio

        from smallestai import AsyncSmallestAI
        from smallestai.atoms.webhooks import PostWebhookRequestEventsItem

        client = AsyncSmallestAI(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.atoms.webhooks.create_a_webhook(
                endpoint="https://example.com/webhook",
                description="Webhook for conversation events",
                events=[PostWebhookRequestEventsItem()],
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_a_webhook(
            endpoint=endpoint, description=description, events=events, request_options=request_options
        )
        return _response.data

    async def delete_a_webhook(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DeleteWebhookIdResponse:
        """
        Delete a webhook by its ID

        Parameters
        ----------
        id : str
            The ID of the webhook to delete

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

        Returns
        -------
        DeleteWebhookIdResponse
            Webhook deleted successfully

        Examples
        --------
        import asyncio

        from smallestai import AsyncSmallestAI

        client = AsyncSmallestAI(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.atoms.webhooks.delete_a_webhook(
                id="id",
            )


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