# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# pyformat: disable

"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from __future__ import annotations
from .. import BaseModel
from ...utils.unions import parse_open_union
from .argumentsdelta import ArgumentsDelta, ArgumentsDeltaTypedDict
from .audiodelta import AudioDelta, AudioDeltaTypedDict
from .codeexecutioncalldelta import (
    CodeExecutionCallDelta,
    CodeExecutionCallDeltaTypedDict,
)
from .codeexecutionresultdelta import (
    CodeExecutionResultDelta,
    CodeExecutionResultDeltaTypedDict,
)
from .documentdelta import DocumentDelta, DocumentDeltaTypedDict
from .filesearchcalldelta import FileSearchCallDelta, FileSearchCallDeltaTypedDict
from .filesearchresultdelta import FileSearchResultDelta, FileSearchResultDeltaTypedDict
from .functionresultdelta import FunctionResultDelta, FunctionResultDeltaTypedDict
from .googlemapscalldelta import GoogleMapsCallDelta, GoogleMapsCallDeltaTypedDict
from .googlemapsresultdelta import GoogleMapsResultDelta, GoogleMapsResultDeltaTypedDict
from .googlesearchcalldelta import GoogleSearchCallDelta, GoogleSearchCallDeltaTypedDict
from .googlesearchresultdelta import (
    GoogleSearchResultDelta,
    GoogleSearchResultDeltaTypedDict,
)
from .imagedelta import ImageDelta, ImageDeltaTypedDict
from .mcpservertoolcalldelta import (
    MCPServerToolCallDelta,
    MCPServerToolCallDeltaTypedDict,
)
from .mcpservertoolresultdelta import (
    MCPServerToolResultDelta,
    MCPServerToolResultDeltaTypedDict,
)
from .retrievalcalldelta import RetrievalCallDelta, RetrievalCallDeltaTypedDict
from .retrievalresultdelta import RetrievalResultDelta, RetrievalResultDeltaTypedDict
from .textannotationdelta import TextAnnotationDelta, TextAnnotationDeltaTypedDict
from .textdelta import TextDelta, TextDeltaTypedDict
from .thoughtsignaturedelta import ThoughtSignatureDelta, ThoughtSignatureDeltaTypedDict
from .thoughtsummarydelta import ThoughtSummaryDelta, ThoughtSummaryDeltaTypedDict
from .urlcontextcalldelta import URLContextCallDelta, URLContextCallDeltaTypedDict
from .urlcontextresultdelta import URLContextResultDelta, URLContextResultDeltaTypedDict
from .videodelta import VideoDelta, VideoDeltaTypedDict
from functools import partial
from pydantic import ConfigDict
from pydantic.functional_validators import BeforeValidator
from typing import Any, Literal, Union
from typing_extensions import Annotated, TypeAliasType


StepDeltaDataTypedDict = TypeAliasType(
    "StepDeltaDataTypedDict",
    Union[
        ArgumentsDeltaTypedDict,
        ThoughtSummaryDeltaTypedDict,
        ThoughtSignatureDeltaTypedDict,
        TextDeltaTypedDict,
        TextAnnotationDeltaTypedDict,
        FileSearchCallDeltaTypedDict,
        FileSearchResultDeltaTypedDict,
        RetrievalResultDeltaTypedDict,
        GoogleMapsCallDeltaTypedDict,
        GoogleMapsResultDeltaTypedDict,
        GoogleSearchCallDeltaTypedDict,
        URLContextCallDeltaTypedDict,
        CodeExecutionCallDeltaTypedDict,
        GoogleSearchResultDeltaTypedDict,
        MCPServerToolResultDeltaTypedDict,
        RetrievalCallDeltaTypedDict,
        MCPServerToolCallDeltaTypedDict,
        DocumentDeltaTypedDict,
        CodeExecutionResultDeltaTypedDict,
        URLContextResultDeltaTypedDict,
        ImageDeltaTypedDict,
        FunctionResultDeltaTypedDict,
        VideoDeltaTypedDict,
        AudioDeltaTypedDict,
    ],
)


class UnknownStepDeltaData(BaseModel):
    r"""A StepDeltaData variant the SDK doesn't recognize. Preserves the raw payload."""

    type: Literal["UNKNOWN"] = "UNKNOWN"
    raw: Any
    is_unknown: Literal[True] = True

    model_config = ConfigDict(frozen=True)


_STEP_DELTA_DATA_VARIANTS: dict[str, Any] = {
    "arguments_delta": ArgumentsDelta,
    "audio": AudioDelta,
    "code_execution_call": CodeExecutionCallDelta,
    "code_execution_result": CodeExecutionResultDelta,
    "document": DocumentDelta,
    "file_search_call": FileSearchCallDelta,
    "file_search_result": FileSearchResultDelta,
    "function_result": FunctionResultDelta,
    "google_maps_call": GoogleMapsCallDelta,
    "google_maps_result": GoogleMapsResultDelta,
    "google_search_call": GoogleSearchCallDelta,
    "google_search_result": GoogleSearchResultDelta,
    "image": ImageDelta,
    "mcp_server_tool_call": MCPServerToolCallDelta,
    "mcp_server_tool_result": MCPServerToolResultDelta,
    "retrieval_call": RetrievalCallDelta,
    "retrieval_result": RetrievalResultDelta,
    "text_annotation_delta": TextAnnotationDelta,
    "text": TextDelta,
    "thought_signature": ThoughtSignatureDelta,
    "thought_summary": ThoughtSummaryDelta,
    "url_context_call": URLContextCallDelta,
    "url_context_result": URLContextResultDelta,
    "video": VideoDelta,
}


StepDeltaData = Annotated[
    Union[
        ArgumentsDelta,
        AudioDelta,
        CodeExecutionCallDelta,
        CodeExecutionResultDelta,
        DocumentDelta,
        FileSearchCallDelta,
        FileSearchResultDelta,
        FunctionResultDelta,
        GoogleMapsCallDelta,
        GoogleMapsResultDelta,
        GoogleSearchCallDelta,
        GoogleSearchResultDelta,
        ImageDelta,
        MCPServerToolCallDelta,
        MCPServerToolResultDelta,
        RetrievalCallDelta,
        RetrievalResultDelta,
        TextAnnotationDelta,
        TextDelta,
        ThoughtSignatureDelta,
        ThoughtSummaryDelta,
        URLContextCallDelta,
        URLContextResultDelta,
        VideoDelta,
        UnknownStepDeltaData,
    ],
    BeforeValidator(
        partial(
            parse_open_union,
            disc_key="type",
            variants=_STEP_DELTA_DATA_VARIANTS,
            unknown_cls=UnknownStepDeltaData,
            union_name="StepDeltaData",
            lenient=True,
        )
    ),
]
