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

from __future__ import annotations
from .messageinputcontentchunks import (
    MessageInputContentChunks,
    MessageInputContentChunksTypedDict,
)
from datetime import datetime
from mistralai.client.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
    UnrecognizedStr,
)
from mistralai.client.utils import validate_const
import pydantic
from pydantic import model_serializer
from pydantic.functional_validators import AfterValidator
from typing import List, Literal, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


Role = Union[
    Literal[
        "assistant",
        "user",
    ],
    UnrecognizedStr,
]


MessageInputEntryContentTypedDict = TypeAliasType(
    "MessageInputEntryContentTypedDict",
    Union[str, List[MessageInputContentChunksTypedDict]],
)


MessageInputEntryContent = TypeAliasType(
    "MessageInputEntryContent", Union[str, List[MessageInputContentChunks]]
)


class MessageInputEntryTypedDict(TypedDict):
    r"""Representation of an input message inside the conversation."""

    role: Role
    content: MessageInputEntryContentTypedDict
    object: Literal["entry"]
    type: Literal["message.input"]
    created_at: NotRequired[datetime]
    completed_at: NotRequired[Nullable[datetime]]
    id: NotRequired[str]
    prefix: NotRequired[bool]


class MessageInputEntry(BaseModel):
    r"""Representation of an input message inside the conversation."""

    role: Role

    content: MessageInputEntryContent

    object: Annotated[
        Annotated[Optional[Literal["entry"]], AfterValidator(validate_const("entry"))],
        pydantic.Field(alias="object"),
    ] = "entry"

    type: Annotated[
        Annotated[
            Optional[Literal["message.input"]],
            AfterValidator(validate_const("message.input")),
        ],
        pydantic.Field(alias="type"),
    ] = "message.input"

    created_at: Optional[datetime] = None

    completed_at: OptionalNullable[datetime] = UNSET

    id: Optional[str] = None

    prefix: Optional[bool] = False

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            ["object", "type", "created_at", "completed_at", "id", "prefix"]
        )
        nullable_fields = set(["completed_at"])
        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))
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

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

        return m


try:
    MessageInputEntry.model_rebuild()
except NameError:
    pass
