# 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 .finish_reason import FinishReason
from .stream_metadata import StreamMetadata
from .stream_usage import StreamUsage


class TextStreamPartWrapper_Error(UniversalBaseModel):
    """
    Wrapper for TextStreamPart 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 TextStreamPartWrapper_Finish(UniversalBaseModel):
    """
    Wrapper for TextStreamPart union for proper serialization.
    """

    type: typing.Literal["finish"] = "finish"
    finish_reason: typing_extensions.Annotated[FinishReason, FieldMetadata(alias="finishReason")] = pydantic.Field(
        alias="finishReason"
    )
    metadata: typing.Optional[StreamMetadata] = None
    total_usage: typing_extensions.Annotated[StreamUsage, FieldMetadata(alias="totalUsage")] = pydantic.Field(
        alias="totalUsage"
    )

    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 TextStreamPartWrapper_FinishStep(UniversalBaseModel):
    """
    Wrapper for TextStreamPart union for proper serialization.
    """

    type: typing.Literal["finish-step"] = "finish-step"
    finish_reason: typing_extensions.Annotated[FinishReason, FieldMetadata(alias="finishReason")] = pydantic.Field(
        alias="finishReason"
    )
    metadata: typing.Optional[StreamMetadata] = None
    usage: StreamUsage

    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 TextStreamPartWrapper_HandlerComplete(UniversalBaseModel):
    """
    Wrapper for TextStreamPart union for proper serialization.
    """

    type: typing.Literal["handler-complete"] = "handler-complete"
    duration_ms: typing_extensions.Annotated[typing.Optional[int], FieldMetadata(alias="durationMs")] = pydantic.Field(
        alias="durationMs", default=None
    )
    error: typing.Optional[str] = None
    event_id: typing_extensions.Annotated[str, FieldMetadata(alias="eventId")] = pydantic.Field(alias="eventId")
    success: bool
    task_id: typing_extensions.Annotated[str, FieldMetadata(alias="taskId")] = pydantic.Field(alias="taskId")

    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 TextStreamPartWrapper_ReasoningDelta(UniversalBaseModel):
    """
    Wrapper for TextStreamPart union for proper serialization.
    """

    type: typing.Literal["reasoning-delta"] = "reasoning-delta"
    id: str
    metadata: typing.Optional[StreamMetadata] = 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 TextStreamPartWrapper_ReasoningEnd(UniversalBaseModel):
    """
    Wrapper for TextStreamPart union for proper serialization.
    """

    type: typing.Literal["reasoning-end"] = "reasoning-end"
    id: str
    metadata: typing.Optional[StreamMetadata] = 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 TextStreamPartWrapper_ReasoningStart(UniversalBaseModel):
    """
    Wrapper for TextStreamPart union for proper serialization.
    """

    type: typing.Literal["reasoning-start"] = "reasoning-start"
    id: str
    metadata: typing.Optional[StreamMetadata] = 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 TextStreamPartWrapper_Start(UniversalBaseModel):
    """
    Wrapper for TextStreamPart union for proper serialization.
    """

    type: typing.Literal["start"] = "start"

    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 TextStreamPartWrapper_StartStep(UniversalBaseModel):
    """
    Wrapper for TextStreamPart union for proper serialization.
    """

    type: typing.Literal["start-step"] = "start-step"
    metadata: typing.Optional[StreamMetadata] = None
    request: typing.Optional[typing.Dict[str, typing.Any]] = None
    warnings: typing.Optional[typing.List[typing.Any]] = 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 TextStreamPartWrapper_TextDelta(UniversalBaseModel):
    """
    Wrapper for TextStreamPart union for proper serialization.
    """

    type: typing.Literal["text-delta"] = "text-delta"
    id: str
    metadata: typing.Optional[StreamMetadata] = 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 TextStreamPartWrapper_TextEnd(UniversalBaseModel):
    """
    Wrapper for TextStreamPart union for proper serialization.
    """

    type: typing.Literal["text-end"] = "text-end"
    id: str
    metadata: typing.Optional[StreamMetadata] = 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 TextStreamPartWrapper_TextStart(UniversalBaseModel):
    """
    Wrapper for TextStreamPart union for proper serialization.
    """

    type: typing.Literal["text-start"] = "text-start"
    id: str
    metadata: typing.Optional[StreamMetadata] = 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 TextStreamPartWrapper_ToolCall(UniversalBaseModel):
    """
    Wrapper for TextStreamPart union for proper serialization.
    """

    type: typing.Literal["tool-call"] = "tool-call"
    input: typing.Dict[str, typing.Any]
    metadata: typing.Optional[StreamMetadata] = None
    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


class TextStreamPartWrapper_ToolInputDelta(UniversalBaseModel):
    """
    Wrapper for TextStreamPart union for proper serialization.
    """

    type: typing.Literal["tool-input-delta"] = "tool-input-delta"
    delta: str
    id: str
    metadata: typing.Optional[StreamMetadata] = 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 TextStreamPartWrapper_ToolInputEnd(UniversalBaseModel):
    """
    Wrapper for TextStreamPart union for proper serialization.
    """

    type: typing.Literal["tool-input-end"] = "tool-input-end"
    id: str
    metadata: typing.Optional[StreamMetadata] = 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 TextStreamPartWrapper_ToolInputStart(UniversalBaseModel):
    """
    Wrapper for TextStreamPart union for proper serialization.
    """

    type: typing.Literal["tool-input-start"] = "tool-input-start"
    id: str
    metadata: typing.Optional[StreamMetadata] = None
    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


class TextStreamPartWrapper_ToolResult(UniversalBaseModel):
    """
    Wrapper for TextStreamPart union for proper serialization.
    """

    type: typing.Literal["tool-result"] = "tool-result"
    metadata: typing.Optional[StreamMetadata] = None
    output: typing.Any
    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


TextStreamPartWrapper = typing_extensions.Annotated[
    typing.Union[
        TextStreamPartWrapper_Error,
        TextStreamPartWrapper_Finish,
        TextStreamPartWrapper_FinishStep,
        TextStreamPartWrapper_HandlerComplete,
        TextStreamPartWrapper_ReasoningDelta,
        TextStreamPartWrapper_ReasoningEnd,
        TextStreamPartWrapper_ReasoningStart,
        TextStreamPartWrapper_Start,
        TextStreamPartWrapper_StartStep,
        TextStreamPartWrapper_TextDelta,
        TextStreamPartWrapper_TextEnd,
        TextStreamPartWrapper_TextStart,
        TextStreamPartWrapper_ToolCall,
        TextStreamPartWrapper_ToolInputDelta,
        TextStreamPartWrapper_ToolInputEnd,
        TextStreamPartWrapper_ToolInputStart,
        TextStreamPartWrapper_ToolResult,
    ],
    pydantic.Field(discriminator="type"),
]
