# This file was auto-generated by Fern from our API Definition.

import datetime as dt
import typing

from ...core.datetime_utils import serialize_datetime
from ...core.pydantic_utilities import pydantic_v1
from .chat_message import ChatMessage
from .finish_reason import FinishReason


class ChatCompletionChoice(pydantic_v1.BaseModel):
    """
    A single chat completion choice. A response will contain one or
    more of these based on the setting of `n`.
    """

    finish_reason: typing.Optional[FinishReason] = None
    index: int = pydantic_v1.Field()
    """
    A unique identifier for the chat completion.Each chunk has the same ID.
    """

    message: ChatMessage = pydantic_v1.Field()
    """
    A chat completion message generated by the model.
    """

    def json(self, **kwargs: typing.Any) -> str:
        kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs}
        return super().json(**kwargs_with_defaults)

    def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
        kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs}
        return super().dict(**kwargs_with_defaults)

    class Config:
        frozen = True
        smart_union = True
        extra = pydantic_v1.Extra.allow
        json_encoders = {dt.datetime: serialize_datetime}
