# 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.actions_enum import ActionsEnum
from ..types.webhook import Webhook
from ..types.webhook_serializer_for_update import WebhookSerializerForUpdate
from .raw_client import AsyncRawWebhooksClient, RawWebhooksClient
from .types.info_webhooks_response import InfoWebhooksResponse

# 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(
        self, *, project: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[Webhook]:
        """
        List all webhooks set up for your organization.

        Parameters
        ----------
        project : typing.Optional[str]
            Project ID

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

        Returns
        -------
        typing.List[Webhook]


        Examples
        --------
        from label_studio_sdk import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.webhooks.list()
        """
        _response = self._raw_client.list(project=project, request_options=request_options)
        return _response.data

    def create(
        self,
        *,
        url: str,
        actions: typing.Optional[typing.Sequence[ActionsEnum]] = OMIT,
        headers: typing.Optional[typing.Any] = OMIT,
        is_active: typing.Optional[bool] = OMIT,
        project: typing.Optional[int] = OMIT,
        send_for_all_actions: typing.Optional[bool] = OMIT,
        send_payload: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Webhook:
        """
        Create a webhook for your organization.

        Parameters
        ----------
        url : str
            URL of webhook

        actions : typing.Optional[typing.Sequence[ActionsEnum]]

        headers : typing.Optional[typing.Any]
            Key Value Json of headers

        is_active : typing.Optional[bool]
            If value is False the webhook is disabled

        project : typing.Optional[int]

        send_for_all_actions : typing.Optional[bool]
            If value is False - used only for actions from WebhookAction

        send_payload : typing.Optional[bool]
            If value is False send only action

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

        Returns
        -------
        Webhook


        Examples
        --------
        from label_studio_sdk import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.webhooks.create(
            url="url",
        )
        """
        _response = self._raw_client.create(
            url=url,
            actions=actions,
            headers=headers,
            is_active=is_active,
            project=project,
            send_for_all_actions=send_for_all_actions,
            send_payload=send_payload,
            request_options=request_options,
        )
        return _response.data

    def info(
        self,
        *,
        organization_only: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> InfoWebhooksResponse:
        """
        Get descriptions of all available webhook actions to set up webhooks.

        Parameters
        ----------
        organization_only : typing.Optional[bool]
            organization-only or not

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

        Returns
        -------
        InfoWebhooksResponse
            Object with webhook action descriptions.

        Examples
        --------
        from label_studio_sdk import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.webhooks.info()
        """
        _response = self._raw_client.info(organization_only=organization_only, request_options=request_options)
        return _response.data

    def get(self, id: int, *, request_options: typing.Optional[RequestOptions] = None) -> Webhook:
        """
        Parameters
        ----------
        id : int

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

        Returns
        -------
        Webhook


        Examples
        --------
        from label_studio_sdk import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.webhooks.get(
            id=1,
        )
        """
        _response = self._raw_client.get(id, request_options=request_options)
        return _response.data

    def delete(self, id: int, *, request_options: typing.Optional[RequestOptions] = None) -> None:
        """
        Parameters
        ----------
        id : int

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

        Returns
        -------
        None

        Examples
        --------
        from label_studio_sdk import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.webhooks.delete(
            id=1,
        )
        """
        _response = self._raw_client.delete(id, request_options=request_options)
        return _response.data

    def update(
        self,
        id: int,
        *,
        actions: typing.Optional[typing.Sequence[ActionsEnum]] = OMIT,
        headers: typing.Optional[typing.Any] = OMIT,
        is_active: typing.Optional[bool] = OMIT,
        send_for_all_actions: typing.Optional[bool] = OMIT,
        send_payload: typing.Optional[bool] = OMIT,
        url: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> WebhookSerializerForUpdate:
        """
        Parameters
        ----------
        id : int

        actions : typing.Optional[typing.Sequence[ActionsEnum]]

        headers : typing.Optional[typing.Any]
            Key Value Json of headers

        is_active : typing.Optional[bool]
            If value is False the webhook is disabled

        send_for_all_actions : typing.Optional[bool]
            If value is False - used only for actions from WebhookAction

        send_payload : typing.Optional[bool]
            If value is False send only action

        url : typing.Optional[str]
            URL of webhook

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

        Returns
        -------
        WebhookSerializerForUpdate


        Examples
        --------
        from label_studio_sdk import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.webhooks.update(
            id=1,
        )
        """
        _response = self._raw_client.update(
            id,
            actions=actions,
            headers=headers,
            is_active=is_active,
            send_for_all_actions=send_for_all_actions,
            send_payload=send_payload,
            url=url,
            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(
        self, *, project: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[Webhook]:
        """
        List all webhooks set up for your organization.

        Parameters
        ----------
        project : typing.Optional[str]
            Project ID

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

        Returns
        -------
        typing.List[Webhook]


        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


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


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

    async def create(
        self,
        *,
        url: str,
        actions: typing.Optional[typing.Sequence[ActionsEnum]] = OMIT,
        headers: typing.Optional[typing.Any] = OMIT,
        is_active: typing.Optional[bool] = OMIT,
        project: typing.Optional[int] = OMIT,
        send_for_all_actions: typing.Optional[bool] = OMIT,
        send_payload: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Webhook:
        """
        Create a webhook for your organization.

        Parameters
        ----------
        url : str
            URL of webhook

        actions : typing.Optional[typing.Sequence[ActionsEnum]]

        headers : typing.Optional[typing.Any]
            Key Value Json of headers

        is_active : typing.Optional[bool]
            If value is False the webhook is disabled

        project : typing.Optional[int]

        send_for_all_actions : typing.Optional[bool]
            If value is False - used only for actions from WebhookAction

        send_payload : typing.Optional[bool]
            If value is False send only action

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

        Returns
        -------
        Webhook


        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


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


        asyncio.run(main())
        """
        _response = await self._raw_client.create(
            url=url,
            actions=actions,
            headers=headers,
            is_active=is_active,
            project=project,
            send_for_all_actions=send_for_all_actions,
            send_payload=send_payload,
            request_options=request_options,
        )
        return _response.data

    async def info(
        self,
        *,
        organization_only: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> InfoWebhooksResponse:
        """
        Get descriptions of all available webhook actions to set up webhooks.

        Parameters
        ----------
        organization_only : typing.Optional[bool]
            organization-only or not

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

        Returns
        -------
        InfoWebhooksResponse
            Object with webhook action descriptions.

        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


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


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

    async def get(self, id: int, *, request_options: typing.Optional[RequestOptions] = None) -> Webhook:
        """
        Parameters
        ----------
        id : int

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

        Returns
        -------
        Webhook


        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.webhooks.get(
                id=1,
            )


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

    async def delete(self, id: int, *, request_options: typing.Optional[RequestOptions] = None) -> None:
        """
        Parameters
        ----------
        id : int

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

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.webhooks.delete(
                id=1,
            )


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

    async def update(
        self,
        id: int,
        *,
        actions: typing.Optional[typing.Sequence[ActionsEnum]] = OMIT,
        headers: typing.Optional[typing.Any] = OMIT,
        is_active: typing.Optional[bool] = OMIT,
        send_for_all_actions: typing.Optional[bool] = OMIT,
        send_payload: typing.Optional[bool] = OMIT,
        url: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> WebhookSerializerForUpdate:
        """
        Parameters
        ----------
        id : int

        actions : typing.Optional[typing.Sequence[ActionsEnum]]

        headers : typing.Optional[typing.Any]
            Key Value Json of headers

        is_active : typing.Optional[bool]
            If value is False the webhook is disabled

        send_for_all_actions : typing.Optional[bool]
            If value is False - used only for actions from WebhookAction

        send_payload : typing.Optional[bool]
            If value is False send only action

        url : typing.Optional[str]
            URL of webhook

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

        Returns
        -------
        WebhookSerializerForUpdate


        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.webhooks.update(
                id=1,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update(
            id,
            actions=actions,
            headers=headers,
            is_active=is_active,
            send_for_all_actions=send_for_all_actions,
            send_payload=send_payload,
            url=url,
            request_options=request_options,
        )
        return _response.data
