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

from __future__ import annotations

import typing

import pydantic
import typing_extensions
from ..core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
from ..core.serialization import FieldMetadata
from .tool_part_state import ToolPartState


class UiMessagePartWrapper_Data(UniversalBaseModel):
    """
    Wrapper for UIMessagePart union for proper serialization.
    """

    type: typing.Literal["data"] = "data"
    data: typing.Any

    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


class UiMessagePartWrapper_Error(UniversalBaseModel):
    """
    Wrapper for UIMessagePart union for proper serialization.
    """

    type: typing.Literal["error"] = "error"
    error: str
    raw_content: typing_extensions.Annotated[typing.Optional[typing.Any], FieldMetadata(alias="rawContent")] = (
        pydantic.Field(alias="rawContent", default=None)
    )

    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


class UiMessagePartWrapper_File(UniversalBaseModel):
    """
    Wrapper for UIMessagePart union for proper serialization.
    """

    type: typing.Literal["file"] = "file"
    media_type: typing_extensions.Annotated[str, FieldMetadata(alias="mediaType")] = pydantic.Field(alias="mediaType")
    url: str

    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


class UiMessagePartWrapper_Reasoning(UniversalBaseModel):
    """
    Wrapper for UIMessagePart union for proper serialization.
    """

    type: typing.Literal["reasoning"] = "reasoning"
    provider_metadata: typing_extensions.Annotated[
        typing.Optional[typing.Dict[str, typing.Any]], FieldMetadata(alias="providerMetadata")
    ] = pydantic.Field(alias="providerMetadata", default=None)
    text: str

    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


class UiMessagePartWrapper_SourceUrl(UniversalBaseModel):
    """
    Wrapper for UIMessagePart union for proper serialization.
    """

    type: typing.Literal["source-url"] = "source-url"
    source_id: typing_extensions.Annotated[str, FieldMetadata(alias="sourceId")] = pydantic.Field(alias="sourceId")
    title: typing.Optional[str] = None
    url: str

    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


class UiMessagePartWrapper_Text(UniversalBaseModel):
    """
    Wrapper for UIMessagePart union for proper serialization.
    """

    type: typing.Literal["text"] = "text"
    text: str

    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


class UiMessagePartWrapper_Tool(UniversalBaseModel):
    """
    Wrapper for UIMessagePart union for proper serialization.
    """

    type: typing.Literal["tool"] = "tool"
    error_text: typing_extensions.Annotated[typing.Optional[str], FieldMetadata(alias="errorText")] = pydantic.Field(
        alias="errorText", default=None
    )
    input: typing.Dict[str, typing.Any]
    output: typing.Optional[typing.Any] = None
    state: ToolPartState
    tool_call_id: typing_extensions.Annotated[str, FieldMetadata(alias="toolCallId")] = pydantic.Field(
        alias="toolCallId"
    )
    tool_name: typing_extensions.Annotated[str, FieldMetadata(alias="toolName")] = pydantic.Field(alias="toolName")

    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


UiMessagePartWrapper = typing_extensions.Annotated[
    typing.Union[
        UiMessagePartWrapper_Data,
        UiMessagePartWrapper_Error,
        UiMessagePartWrapper_File,
        UiMessagePartWrapper_Reasoning,
        UiMessagePartWrapper_SourceUrl,
        UiMessagePartWrapper_Text,
        UiMessagePartWrapper_Tool,
    ],
    pydantic.Field(discriminator="type"),
]
