# 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 .codeexecutioncallstep import CodeExecutionCallStep, CodeExecutionCallStepParam
from .codeexecutionresultstep import (
    CodeExecutionResultStep,
    CodeExecutionResultStepParam,
)
from .filesearchcallstep import FileSearchCallStep, FileSearchCallStepParam
from .filesearchresultstep import FileSearchResultStep, FileSearchResultStepParam
from .functioncallstep import FunctionCallStep, FunctionCallStepParam
from .functionresultstep import FunctionResultStep, FunctionResultStepParam
from .googlemapscallstep import GoogleMapsCallStep, GoogleMapsCallStepParam
from .googlemapsresultstep import GoogleMapsResultStep, GoogleMapsResultStepParam
from .googlesearchcallstep import GoogleSearchCallStep, GoogleSearchCallStepParam
from .googlesearchresultstep import GoogleSearchResultStep, GoogleSearchResultStepParam
from .mcpservertoolcallstep import MCPServerToolCallStep, MCPServerToolCallStepParam
from .mcpservertoolresultstep import (
    MCPServerToolResultStep,
    MCPServerToolResultStepParam,
)
from .modeloutputstep import ModelOutputStep, ModelOutputStepParam
from .thoughtstep import ThoughtStep, ThoughtStepParam
from .urlcontextcallstep import URLContextCallStep, URLContextCallStepParam
from .urlcontextresultstep import URLContextResultStep, URLContextResultStepParam
from .userinputstep import UserInputStep, UserInputStepParam
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


StepParam = TypeAliasType(
    "StepParam",
    Union[
        UserInputStepParam,
        FileSearchCallStepParam,
        ModelOutputStepParam,
        ThoughtStepParam,
        FileSearchResultStepParam,
        CodeExecutionCallStepParam,
        URLContextCallStepParam,
        GoogleMapsCallStepParam,
        FunctionCallStepParam,
        GoogleMapsResultStepParam,
        MCPServerToolCallStepParam,
        GoogleSearchCallStepParam,
        FunctionResultStepParam,
        CodeExecutionResultStepParam,
        URLContextResultStepParam,
        GoogleSearchResultStepParam,
        MCPServerToolResultStepParam,
    ],
)
r"""A step in the interaction."""


class UnknownStep(BaseModel):
    r"""A Step 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_VARIANTS: dict[str, Any] = {
    "user_input": UserInputStep,
    "model_output": ModelOutputStep,
    "thought": ThoughtStep,
    "function_call": FunctionCallStep,
    "code_execution_call": CodeExecutionCallStep,
    "url_context_call": URLContextCallStep,
    "mcp_server_tool_call": MCPServerToolCallStep,
    "google_search_call": GoogleSearchCallStep,
    "file_search_call": FileSearchCallStep,
    "google_maps_call": GoogleMapsCallStep,
    "function_result": FunctionResultStep,
    "code_execution_result": CodeExecutionResultStep,
    "url_context_result": URLContextResultStep,
    "google_search_result": GoogleSearchResultStep,
    "mcp_server_tool_result": MCPServerToolResultStep,
    "file_search_result": FileSearchResultStep,
    "google_maps_result": GoogleMapsResultStep,
}


Step = Annotated[
    Union[
        UserInputStep,
        ModelOutputStep,
        ThoughtStep,
        FunctionCallStep,
        CodeExecutionCallStep,
        URLContextCallStep,
        MCPServerToolCallStep,
        GoogleSearchCallStep,
        FileSearchCallStep,
        GoogleMapsCallStep,
        FunctionResultStep,
        CodeExecutionResultStep,
        URLContextResultStep,
        GoogleSearchResultStep,
        MCPServerToolResultStep,
        FileSearchResultStep,
        GoogleMapsResultStep,
        UnknownStep,
    ],
    BeforeValidator(
        partial(
            parse_open_union,
            disc_key="type",
            variants=_STEP_VARIANTS,
            unknown_cls=UnknownStep,
            union_name="Step",
            lenient=True,
        )
    ),
]
r"""A step in the interaction."""
