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

from __future__ import annotations

import typing
import uuid

import pydantic
import typing_extensions
from ...core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
from ...core.serialization import FieldMetadata
from .data_filter import DataFilter
from .error_chunk_data import ErrorChunkData
from .policy_trigger import PolicyTrigger
from .referenced_source import ReferencedSource
from .web_search_result import WebSearchResult


class StreamingChunk_Initial(UniversalBaseModel):
    event: typing.Literal["initial"] = "initial"
    conversation_id: typing_extensions.Annotated[str, FieldMetadata(alias="conversationId")]
    warnings: typing.List[str]
    web_search_results: typing_extensions.Annotated[
        typing.List[WebSearchResult], FieldMetadata(alias="webSearchResults")
    ]
    data_filters: typing_extensions.Annotated[typing.Optional[DataFilter], FieldMetadata(alias="dataFilters")] = 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 StreamingChunk_DataChunk(UniversalBaseModel):
    event: typing.Literal["data_chunk"] = "data_chunk"
    chunk: 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 StreamingChunk_EndOfMessage(UniversalBaseModel):
    event: typing.Literal["end_of_message"] = "end_of_message"

    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 StreamingChunk_FinalChunk(UniversalBaseModel):
    event: typing.Literal["final_chunk"] = "final_chunk"
    sources: typing.List[ReferencedSource]

    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 StreamingChunk_Blocked(UniversalBaseModel):
    event: typing.Literal["blocked"] = "blocked"
    conversation_id: typing_extensions.Annotated[uuid.UUID, FieldMetadata(alias="conversationId")]
    warnings: typing.List[str]
    blocks: typing.List[str]
    policy_triggers: typing_extensions.Annotated[typing.List[PolicyTrigger], FieldMetadata(alias="policyTriggers")]

    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 StreamingChunk_ErrorChunk(UniversalBaseModel):
    event: typing.Literal["error_chunk"] = "error_chunk"
    error: ErrorChunkData

    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


StreamingChunk = typing.Union[
    StreamingChunk_Initial,
    StreamingChunk_DataChunk,
    StreamingChunk_EndOfMessage,
    StreamingChunk_FinalChunk,
    StreamingChunk_Blocked,
    StreamingChunk_ErrorChunk,
]
