# 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 .errorevent import ErrorEvent, ErrorEventTypedDict
from .interactioncompletedevent import (
    InteractionCompletedEvent,
    InteractionCompletedEventTypedDict,
)
from .interactioncreatedevent import (
    InteractionCreatedEvent,
    InteractionCreatedEventTypedDict,
)
from .interactionstatusupdate import (
    InteractionStatusUpdate,
    InteractionStatusUpdateTypedDict,
)
from .stepdelta import StepDelta, StepDeltaTypedDict
from .stepstart import StepStart, StepStartTypedDict
from .stepstop import StepStop, StepStopTypedDict
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


InteractionSSEEventTypedDict = TypeAliasType(
    "InteractionSSEEventTypedDict",
    Union[
        InteractionCreatedEventTypedDict,
        InteractionCompletedEventTypedDict,
        ErrorEventTypedDict,
        InteractionStatusUpdateTypedDict,
        StepStartTypedDict,
        StepDeltaTypedDict,
        StepStopTypedDict,
    ],
)


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

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

    model_config = ConfigDict(frozen=True)


_INTERACTION_SSE_EVENT_VARIANTS: dict[str, Any] = {
    "interaction.created": InteractionCreatedEvent,
    "interaction.completed": InteractionCompletedEvent,
    "interaction.status_update": InteractionStatusUpdate,
    "error": ErrorEvent,
    "step.start": StepStart,
    "step.delta": StepDelta,
    "step.stop": StepStop,
}


InteractionSSEEvent = Annotated[
    Union[
        InteractionCreatedEvent,
        InteractionCompletedEvent,
        InteractionStatusUpdate,
        ErrorEvent,
        StepStart,
        StepDelta,
        StepStop,
        UnknownInteractionSSEEvent,
    ],
    BeforeValidator(
        partial(
            parse_open_union,
            disc_key="event_type",
            variants=_INTERACTION_SSE_EVENT_VARIANTS,
            unknown_cls=UnknownInteractionSSEEvent,
            union_name="InteractionSSEEvent",
            lenient=True,
        )
    ),
]
