# 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.delete_message_response import DeleteMessageResponse
from ..types.messages_list_response import MessagesListResponse
from ..types.update_message_response import UpdateMessageResponse
from .raw_client import AsyncRawMessagesClient, RawMessagesClient

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


class MessagesClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawMessagesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawMessagesClient
        """
        return self._raw_client

    def get_thread_messages(
        self,
        thread_id: str,
        *,
        limit: typing.Optional[int] = None,
        order: typing.Optional[str] = None,
        after: typing.Optional[str] = None,
        before: typing.Optional[str] = None,
        output_mode: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> MessagesListResponse:
        """
        Retrieve all messages from a specific thread with pagination support.

        Parameters
        ----------
        thread_id : str
            The unique identifier of the thread to retrieve messages from

        limit : typing.Optional[int]
            Number of messages to return per page. Must be between 1 and 100.

        order : typing.Optional[str]
            Sort order for messages. 'asc' = oldest first, 'desc' = newest first.

        after : typing.Optional[str]
            Cursor for pagination. Returns messages created after this message ID.

        before : typing.Optional[str]
            Cursor for pagination. Returns messages created before this message ID.

        output_mode : typing.Optional[str]
            Response format mode. 'text' (default, rich text), 'plain' (no formatting), 'blocks' or 'structured' (typed blocks). Controls response_blocks field inclusion.

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

        Returns
        -------
        MessagesListResponse
            Messages retrieved successfully

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.messages.get_thread_messages(
            thread_id="thread_id",
        )
        """
        _response = self._raw_client.get_thread_messages(
            thread_id,
            limit=limit,
            order=order,
            after=after,
            before=before,
            output_mode=output_mode,
            request_options=request_options,
        )
        return _response.data

    def delete_message(
        self, thread_id: str, message_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DeleteMessageResponse:
        """
        Delete a specific message from a thread with proper authorization and audit trails.

        Parameters
        ----------
        thread_id : str
            The unique identifier of the thread containing the message

        message_id : str
            The unique identifier of the message to delete

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

        Returns
        -------
        DeleteMessageResponse
            Message deleted successfully

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.messages.delete_message(
            thread_id="thread_id",
            message_id="message_id",
        )
        """
        _response = self._raw_client.delete_message(thread_id, message_id, request_options=request_options)
        return _response.data

    def update_message(
        self,
        thread_id: str,
        message_id: str,
        *,
        content: typing.Optional[str] = OMIT,
        metadata: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpdateMessageResponse:
        """
        Edit message content and metadata after creation with proper authorization and validation.

        Parameters
        ----------
        thread_id : str
            The unique identifier of the thread containing the message

        message_id : str
            The unique identifier of the message to update

        content : typing.Optional[str]
            New message content

        metadata : typing.Optional[typing.Dict[str, typing.Any]]
            Metadata to merge

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

        Returns
        -------
        UpdateMessageResponse
            Message updated successfully

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.messages.update_message(
            thread_id="thread_id",
            message_id="message_id",
        )
        """
        _response = self._raw_client.update_message(
            thread_id, message_id, content=content, metadata=metadata, request_options=request_options
        )
        return _response.data


class AsyncMessagesClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawMessagesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawMessagesClient
        """
        return self._raw_client

    async def get_thread_messages(
        self,
        thread_id: str,
        *,
        limit: typing.Optional[int] = None,
        order: typing.Optional[str] = None,
        after: typing.Optional[str] = None,
        before: typing.Optional[str] = None,
        output_mode: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> MessagesListResponse:
        """
        Retrieve all messages from a specific thread with pagination support.

        Parameters
        ----------
        thread_id : str
            The unique identifier of the thread to retrieve messages from

        limit : typing.Optional[int]
            Number of messages to return per page. Must be between 1 and 100.

        order : typing.Optional[str]
            Sort order for messages. 'asc' = oldest first, 'desc' = newest first.

        after : typing.Optional[str]
            Cursor for pagination. Returns messages created after this message ID.

        before : typing.Optional[str]
            Cursor for pagination. Returns messages created before this message ID.

        output_mode : typing.Optional[str]
            Response format mode. 'text' (default, rich text), 'plain' (no formatting), 'blocks' or 'structured' (typed blocks). Controls response_blocks field inclusion.

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

        Returns
        -------
        MessagesListResponse
            Messages retrieved successfully

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.messages.get_thread_messages(
                thread_id="thread_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_thread_messages(
            thread_id,
            limit=limit,
            order=order,
            after=after,
            before=before,
            output_mode=output_mode,
            request_options=request_options,
        )
        return _response.data

    async def delete_message(
        self, thread_id: str, message_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DeleteMessageResponse:
        """
        Delete a specific message from a thread with proper authorization and audit trails.

        Parameters
        ----------
        thread_id : str
            The unique identifier of the thread containing the message

        message_id : str
            The unique identifier of the message to delete

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

        Returns
        -------
        DeleteMessageResponse
            Message deleted successfully

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.messages.delete_message(
                thread_id="thread_id",
                message_id="message_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.delete_message(thread_id, message_id, request_options=request_options)
        return _response.data

    async def update_message(
        self,
        thread_id: str,
        message_id: str,
        *,
        content: typing.Optional[str] = OMIT,
        metadata: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpdateMessageResponse:
        """
        Edit message content and metadata after creation with proper authorization and validation.

        Parameters
        ----------
        thread_id : str
            The unique identifier of the thread containing the message

        message_id : str
            The unique identifier of the message to update

        content : typing.Optional[str]
            New message content

        metadata : typing.Optional[typing.Dict[str, typing.Any]]
            Metadata to merge

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

        Returns
        -------
        UpdateMessageResponse
            Message updated successfully

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.messages.update_message(
                thread_id="thread_id",
                message_id="message_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_message(
            thread_id, message_id, content=content, metadata=metadata, request_options=request_options
        )
        return _response.data
