"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
# @generated-id: 1b39f46f529f

from __future__ import annotations
from .jsonpatchadd import JSONPatchAdd, JSONPatchAddTypedDict
from .jsonpatchappend import JSONPatchAppend, JSONPatchAppendTypedDict
from .jsonpatchremove import JSONPatchRemove, JSONPatchRemoveTypedDict
from .jsonpatchreplace import JSONPatchReplace, JSONPatchReplaceTypedDict
from functools import partial
from mistralai.client.types import BaseModel
from mistralai.client.utils import validate_const
from mistralai.client.utils.unions import parse_open_union
import pydantic
from pydantic import ConfigDict
from pydantic.functional_validators import AfterValidator, BeforeValidator
from typing import Any, List, Literal, Union
from typing_extensions import Annotated, TypeAliasType, TypedDict


JSONPatchPayloadResponseValueTypedDict = TypeAliasType(
    "JSONPatchPayloadResponseValueTypedDict",
    Union[
        JSONPatchAppendTypedDict,
        JSONPatchAddTypedDict,
        JSONPatchReplaceTypedDict,
        JSONPatchRemoveTypedDict,
    ],
)


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

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

    model_config = ConfigDict(frozen=True)


_JSON_PATCH_PAYLOAD_RESPONSE_VALUE_VARIANTS: dict[str, Any] = {
    "add": JSONPatchAdd,
    "append": JSONPatchAppend,
    "remove": JSONPatchRemove,
    "replace": JSONPatchReplace,
}


JSONPatchPayloadResponseValue = Annotated[
    Union[
        JSONPatchAdd,
        JSONPatchAppend,
        JSONPatchRemove,
        JSONPatchReplace,
        UnknownJSONPatchPayloadResponseValue,
    ],
    BeforeValidator(
        partial(
            parse_open_union,
            disc_key="op",
            variants=_JSON_PATCH_PAYLOAD_RESPONSE_VALUE_VARIANTS,
            unknown_cls=UnknownJSONPatchPayloadResponseValue,
            union_name="JSONPatchPayloadResponseValue",
        )
    ),
]


class JSONPatchPayloadResponseTypedDict(TypedDict):
    r"""A payload containing a list of JSON Patch operations.

    Used for streaming incremental updates to workflow state.
    """

    value: List[JSONPatchPayloadResponseValueTypedDict]
    r"""The list of JSON Patch operations to apply in order."""
    type: Literal["json_patch"]
    r"""Discriminator indicating this is a JSON Patch payload."""


class JSONPatchPayloadResponse(BaseModel):
    r"""A payload containing a list of JSON Patch operations.

    Used for streaming incremental updates to workflow state.
    """

    value: List[JSONPatchPayloadResponseValue]
    r"""The list of JSON Patch operations to apply in order."""

    type: Annotated[
        Annotated[Literal["json_patch"], AfterValidator(validate_const("json_patch"))],
        pydantic.Field(alias="type"),
    ] = "json_patch"
    r"""Discriminator indicating this is a JSON Patch payload."""


try:
    JSONPatchPayloadResponse.model_rebuild()
except NameError:
    pass
