"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from __future__ import annotations
from .deltamessage import DeltaMessage, DeltaMessageTypedDict
from mistralai.gcp.client.types import (
    BaseModel,
    Nullable,
    UNSET_SENTINEL,
    UnrecognizedStr,
)
from pydantic import model_serializer
from typing import Literal, Union
from typing_extensions import TypedDict


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


class CompletionResponseStreamChoiceTypedDict(TypedDict):
    index: int
    delta: DeltaMessageTypedDict
    finish_reason: Nullable[CompletionResponseStreamChoiceFinishReason]


class CompletionResponseStreamChoice(BaseModel):
    index: int

    delta: DeltaMessage

    finish_reason: Nullable[CompletionResponseStreamChoiceFinishReason]

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        serialized = handler(self)
        m = {}

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

            if val != UNSET_SENTINEL:
                m[k] = val

        return m
