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

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.unions import parse_open_union
from pydantic import ConfigDict
from pydantic.functional_validators import BeforeValidator
from typing import Any, Literal, Union
from typing_extensions import Annotated, TypeAliasType


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


class UnknownJSONPatch(BaseModel):
    r"""A JSONPatch 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_VARIANTS: dict[str, Any] = {
    "add": JSONPatchAdd,
    "append": JSONPatchAppend,
    "remove": JSONPatchRemove,
    "replace": JSONPatchReplace,
}


JSONPatch = Annotated[
    Union[
        JSONPatchAdd,
        JSONPatchAppend,
        JSONPatchRemove,
        JSONPatchReplace,
        UnknownJSONPatch,
    ],
    BeforeValidator(
        partial(
            parse_open_union,
            disc_key="op",
            variants=_JSON_PATCH_VARIANTS,
            unknown_cls=UnknownJSONPatch,
            union_name="JSONPatch",
        )
    ),
]
