# 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.alert_public import AlertPublic
from ..types.alert_trigger_write import AlertTriggerWrite
from ..types.webhook_write import WebhookWrite
from .raw_client import AsyncRawAlertsClient, RawAlertsClient

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


class AlertsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawAlertsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawAlertsClient
        """
        return self._raw_client

    def create_alert(
        self,
        *,
        name: str,
        webhook: WebhookWrite,
        id: typing.Optional[str] = OMIT,
        enabled: typing.Optional[bool] = OMIT,
        triggers: typing.Optional[typing.Sequence[AlertTriggerWrite]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Create alert

        Parameters
        ----------
        name : str

        webhook : WebhookWrite

        id : typing.Optional[str]

        enabled : typing.Optional[bool]

        triggers : typing.Optional[typing.Sequence[AlertTriggerWrite]]

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

        Returns
        -------
        None

        Examples
        --------
        from Opik import OpikApi
        from Opik import WebhookWrite
        client = OpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        client.alerts.create_alert(name='name', webhook=WebhookWrite(url='url', secret_token='secret_token', ), )
        """
        _response = self._raw_client.create_alert(
            name=name, webhook=webhook, id=id, enabled=enabled, triggers=triggers, request_options=request_options
        )
        return _response.data

    def delete_alert_batch(
        self, *, ids: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Delete multiple alerts by their IDs

        Parameters
        ----------
        ids : typing.Sequence[str]

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

        Returns
        -------
        None

        Examples
        --------
        from Opik import OpikApi
        client = OpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        client.alerts.delete_alert_batch(ids=['ids'], )
        """
        _response = self._raw_client.delete_alert_batch(ids=ids, request_options=request_options)
        return _response.data

    def get_alert_by_id(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> AlertPublic:
        """
        Get Alert by id

        Parameters
        ----------
        id : str

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

        Returns
        -------
        AlertPublic
            Alert resource

        Examples
        --------
        from Opik import OpikApi
        client = OpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        client.alerts.get_alert_by_id(id='id', )
        """
        _response = self._raw_client.get_alert_by_id(id, request_options=request_options)
        return _response.data


class AsyncAlertsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawAlertsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawAlertsClient
        """
        return self._raw_client

    async def create_alert(
        self,
        *,
        name: str,
        webhook: WebhookWrite,
        id: typing.Optional[str] = OMIT,
        enabled: typing.Optional[bool] = OMIT,
        triggers: typing.Optional[typing.Sequence[AlertTriggerWrite]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Create alert

        Parameters
        ----------
        name : str

        webhook : WebhookWrite

        id : typing.Optional[str]

        enabled : typing.Optional[bool]

        triggers : typing.Optional[typing.Sequence[AlertTriggerWrite]]

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

        Returns
        -------
        None

        Examples
        --------
        from Opik import AsyncOpikApi
        from Opik import WebhookWrite
        import asyncio
        client = AsyncOpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        async def main() -> None:
            await client.alerts.create_alert(name='name', webhook=WebhookWrite(url='url', secret_token='secret_token', ), )
        asyncio.run(main())
        """
        _response = await self._raw_client.create_alert(
            name=name, webhook=webhook, id=id, enabled=enabled, triggers=triggers, request_options=request_options
        )
        return _response.data

    async def delete_alert_batch(
        self, *, ids: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Delete multiple alerts by their IDs

        Parameters
        ----------
        ids : typing.Sequence[str]

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

        Returns
        -------
        None

        Examples
        --------
        from Opik import AsyncOpikApi
        import asyncio
        client = AsyncOpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        async def main() -> None:
            await client.alerts.delete_alert_batch(ids=['ids'], )
        asyncio.run(main())
        """
        _response = await self._raw_client.delete_alert_batch(ids=ids, request_options=request_options)
        return _response.data

    async def get_alert_by_id(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> AlertPublic:
        """
        Get Alert by id

        Parameters
        ----------
        id : str

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

        Returns
        -------
        AlertPublic
            Alert resource

        Examples
        --------
        from Opik import AsyncOpikApi
        import asyncio
        client = AsyncOpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        async def main() -> None:
            await client.alerts.get_alert_by_id(id='id', )
        asyncio.run(main())
        """
        _response = await self._raw_client.get_alert_by_id(id, request_options=request_options)
        return _response.data
