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

from __future__ import annotations
from ..core.unchecked_base_model import UncheckedBaseModel
import typing
from .user_message_content import UserMessageContent
from ..core.pydantic_utilities import IS_PYDANTIC_V2
import pydantic
from .tool_call_v2 import ToolCallV2
from .assistant_message_content import AssistantMessageContent
from .citation import Citation
from .system_message_content import SystemMessageContent
from .tool_message_v2content import ToolMessageV2Content
import typing_extensions
from ..core.unchecked_base_model import UnionMetadata


class UserChatMessageV2(UncheckedBaseModel):
    """
    Represents a single message in the chat history from a given role.
    """

    role: typing.Literal["user"] = "user"
    content: UserMessageContent

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

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


class AssistantChatMessageV2(UncheckedBaseModel):
    """
    Represents a single message in the chat history from a given role.
    """

    role: typing.Literal["assistant"] = "assistant"
    tool_calls: typing.Optional[typing.List[ToolCallV2]] = None
    tool_plan: typing.Optional[str] = None
    content: typing.Optional[AssistantMessageContent] = None
    citations: typing.Optional[typing.List[Citation]] = None

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

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


class SystemChatMessageV2(UncheckedBaseModel):
    """
    Represents a single message in the chat history from a given role.
    """

    role: typing.Literal["system"] = "system"
    content: SystemMessageContent

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

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


class ToolChatMessageV2(UncheckedBaseModel):
    """
    Represents a single message in the chat history from a given role.
    """

    role: typing.Literal["tool"] = "tool"
    tool_call_id: str
    content: ToolMessageV2Content

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

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


ChatMessageV2 = typing_extensions.Annotated[
    typing.Union[UserChatMessageV2, AssistantChatMessageV2, SystemChatMessageV2, ToolChatMessageV2],
    UnionMetadata(discriminant="role"),
]
