# This file was auto-generated by Fern from our API Definition.

import datetime as dt
import typing

import pydantic
from ..core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
from .message_response_role import MessageResponseRole


class MessageResponse(UniversalBaseModel):
    """
    Single message response schema.

    Fields tool_calls and iterations are conditionally included only for assistant messages.
    """

    id: str = pydantic.Field()
    """
    Message ID with msg_ prefix
    """

    created_at: dt.datetime = pydantic.Field()
    """
    Creation timestamp
    """

    thread_id: str = pydantic.Field()
    """
    Thread ID with thread_ prefix
    """

    role: MessageResponseRole = pydantic.Field()
    """
    Message role
    """

    content: str = pydantic.Field()
    """
    Message text content
    """

    attachments: typing.Optional[typing.List[typing.Dict[str, typing.Any]]] = pydantic.Field(default=None)
    """
    File attachments
    """

    metadata: typing.Optional[typing.Dict[str, typing.Any]] = pydantic.Field(default=None)
    """
    Custom metadata
    """

    tool_calls: typing.Optional[typing.List[typing.Dict[str, typing.Any]]] = pydantic.Field(default=None)
    """
    Tool invocations (assistant only)
    """

    iterations: typing.Optional[typing.List[typing.Dict[str, typing.Any]]] = pydantic.Field(default=None)
    """
    Reasoning steps (assistant only)
    """

    response_blocks: typing.Optional[typing.List[typing.Dict[str, typing.Any]]] = pydantic.Field(default=None)
    """
    Structured response blocks (when output_mode=structured)
    """

    if IS_PYDANTIC_V2:
        model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True)  # type: ignore # Pydantic v2
    else:

        class Config:
            frozen = True
            smart_union = True
            extra = pydantic.Extra.allow
