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

import typing

import pydantic
import typing_extensions
from ..core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
from ..core.serialization import FieldMetadata
from .ui_message_metadata import UiMessageMetadata
from .ui_message_part_wrapper import UiMessagePartWrapper
from .ui_message_role import UiMessageRole


class UiMessage(UniversalBaseModel):
    """
    Vercel AI SDK compatible message format.

    Based on: https://ai-sdk.dev/docs/reference/ai-sdk-core/ui-message
    with extensions for our use case.
    """

    created_at: typing_extensions.Annotated[typing.Optional[str], FieldMetadata(alias="createdAt")] = pydantic.Field(
        alias="createdAt", default=None
    )
    """
    ISO timestamp when created
    """

    id: str = pydantic.Field()
    """
    Unique message ID
    """

    metadata: typing.Optional[UiMessageMetadata] = pydantic.Field(default=None)
    """
    Message metadata
    """

    parts: typing.List[UiMessagePartWrapper] = pydantic.Field()
    """
    Content parts of the message
    """

    role: UiMessageRole = pydantic.Field()
    """
    Role of the message author
    """

    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
