# 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.publish_raw_event_response import PublishRawEventResponse
from .raw_client import AsyncRawRawEventsClient, RawRawEventsClient

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


class RawEventsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawRawEventsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawRawEventsClient
        """
        return self._raw_client

    def publish_raw_event(
        self,
        *,
        raw_event: typing.Dict[str, typing.Any],
        sdk_type: str,
        sdk_version: str,
        task_id: str,
        idempotency_key: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> PublishRawEventResponse:
        """
        Publish a raw SDK event for transformation and streaming.

            This endpoint replaces the deprecated `/stream-events` endpoint.
            Events are transformed via SDK-specific adapters (based on `sdk_type` and `sdk_version`)
            and the resulting stream parts are published to Redis for real-time consumption.

            Messages that should be stored (e.g., AssistantMessage, UserMessage) are
            automatically persisted to MongoDB for later retrieval.

            **Supported SDK Types:**
            - `claude`: Claude Agent SDK messages (StreamEvent, AssistantMessage, etc.)
            - `codex`: Codex SDK thread events (`item.*`, `turn.*`, `thread.*`)
            - `terminal_use`: Direct UIMessage format (Vercel-compatible)

            **What gets stored:**
            - AssistantMessage, UserMessage, ResultMessage, SystemMessage

            **What does NOT get stored:**
            - StreamEvent (ephemeral streaming deltas)

            Requires `update` permission on the task.

        Parameters
        ----------
        raw_event : typing.Dict[str, typing.Any]
            The raw SDK event payload

        sdk_type : str
            SDK type identifier (e.g., 'claude', 'codex', 'terminal_use')

        sdk_version : str
            SDK version in semver format (e.g., '0.1.22')

        task_id : str
            Task ID to publish the event to

        idempotency_key : typing.Optional[str]
            Optional idempotency key for request-level deduplication

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

        Returns
        -------
        PublishRawEventResponse
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.raw_events.publish_raw_event(
            raw_event={"key": "value"},
            sdk_type="sdk_type",
            sdk_version="sdk_version",
            task_id="task_id",
        )
        """
        _response = self._raw_client.publish_raw_event(
            raw_event=raw_event,
            sdk_type=sdk_type,
            sdk_version=sdk_version,
            task_id=task_id,
            idempotency_key=idempotency_key,
            request_options=request_options,
        )
        return _response.data


class AsyncRawEventsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawRawEventsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawRawEventsClient
        """
        return self._raw_client

    async def publish_raw_event(
        self,
        *,
        raw_event: typing.Dict[str, typing.Any],
        sdk_type: str,
        sdk_version: str,
        task_id: str,
        idempotency_key: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> PublishRawEventResponse:
        """
        Publish a raw SDK event for transformation and streaming.

            This endpoint replaces the deprecated `/stream-events` endpoint.
            Events are transformed via SDK-specific adapters (based on `sdk_type` and `sdk_version`)
            and the resulting stream parts are published to Redis for real-time consumption.

            Messages that should be stored (e.g., AssistantMessage, UserMessage) are
            automatically persisted to MongoDB for later retrieval.

            **Supported SDK Types:**
            - `claude`: Claude Agent SDK messages (StreamEvent, AssistantMessage, etc.)
            - `codex`: Codex SDK thread events (`item.*`, `turn.*`, `thread.*`)
            - `terminal_use`: Direct UIMessage format (Vercel-compatible)

            **What gets stored:**
            - AssistantMessage, UserMessage, ResultMessage, SystemMessage

            **What does NOT get stored:**
            - StreamEvent (ephemeral streaming deltas)

            Requires `update` permission on the task.

        Parameters
        ----------
        raw_event : typing.Dict[str, typing.Any]
            The raw SDK event payload

        sdk_type : str
            SDK type identifier (e.g., 'claude', 'codex', 'terminal_use')

        sdk_version : str
            SDK version in semver format (e.g., '0.1.22')

        task_id : str
            Task ID to publish the event to

        idempotency_key : typing.Optional[str]
            Optional idempotency key for request-level deduplication

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

        Returns
        -------
        PublishRawEventResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.raw_events.publish_raw_event(
                raw_event={"key": "value"},
                sdk_type="sdk_type",
                sdk_version="sdk_version",
                task_id="task_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.publish_raw_event(
            raw_event=raw_event,
            sdk_type=sdk_type,
            sdk_version=sdk_version,
            task_id=task_id,
            idempotency_key=idempotency_key,
            request_options=request_options,
        )
        return _response.data
