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

from __future__ import annotations
from .assistantmessage import AssistantMessage, AssistantMessageTypedDict
from mistralai.client.types import BaseModel, UNSET_SENTINEL, UnrecognizedStr
from pydantic import model_serializer
from typing import List, Literal, Optional, Union
from typing_extensions import NotRequired, TypeAliasType, TypedDict


ChatCompletionChoiceFinishReason2 = Union[
    Literal[
        "stop",
        "length",
        "model_length",
        "error",
        "tool_calls",
    ],
    UnrecognizedStr,
]


class ChatCompletionChoice2TypedDict(TypedDict):
    index: int
    finish_reason: ChatCompletionChoiceFinishReason2
    messages: List[AssistantMessageTypedDict]
    message: NotRequired[AssistantMessageTypedDict]


class ChatCompletionChoice2(BaseModel):
    index: int

    finish_reason: ChatCompletionChoiceFinishReason2

    messages: List[AssistantMessage]

    message: Optional[AssistantMessage] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["message"])
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


ChatCompletionChoiceFinishReason1 = Union[
    Literal[
        "stop",
        "length",
        "model_length",
        "error",
        "tool_calls",
    ],
    UnrecognizedStr,
]


class ChatCompletionChoice1TypedDict(TypedDict):
    index: int
    message: AssistantMessageTypedDict
    finish_reason: ChatCompletionChoiceFinishReason1
    messages: NotRequired[List[AssistantMessageTypedDict]]


class ChatCompletionChoice1(BaseModel):
    index: int

    message: AssistantMessage

    finish_reason: ChatCompletionChoiceFinishReason1

    messages: Optional[List[AssistantMessage]] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["messages"])
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


ChatCompletionChoiceUnionTypedDict = TypeAliasType(
    "ChatCompletionChoiceUnionTypedDict",
    Union[ChatCompletionChoice1TypedDict, ChatCompletionChoice2TypedDict],
)


ChatCompletionChoiceUnion = TypeAliasType(
    "ChatCompletionChoiceUnion", Union[ChatCompletionChoice1, ChatCompletionChoice2]
)
