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

import typing

import pydantic
import typing_extensions
from ..core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
from ..core.serialization import FieldMetadata
from .usage import Usage


class UiMessageMetadata(UniversalBaseModel):
    """
    Metadata for a UIMessage.
    """

    cost_usd: typing_extensions.Annotated[typing.Optional[float], FieldMetadata(alias="costUsd")] = pydantic.Field(
        alias="costUsd", default=None
    )
    """
    Cost in USD for this message
    """

    duration_ms: typing_extensions.Annotated[typing.Optional[int], FieldMetadata(alias="durationMs")] = pydantic.Field(
        alias="durationMs", default=None
    )
    """
    Duration in milliseconds
    """

    model: typing.Optional[str] = pydantic.Field(default=None)
    """
    Model used to generate message
    """

    parent_tool_use_id: typing_extensions.Annotated[typing.Optional[str], FieldMetadata(alias="parentToolUseId")] = (
        pydantic.Field(alias="parentToolUseId", default=None)
    )
    """
    Parent tool use ID for subagent context
    """

    usage: typing.Optional[Usage] = pydantic.Field(default=None)
    """
    Token usage for this message
    """

    if IS_PYDANTIC_V2:
        model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True)  # type: ignore # Pydantic v2
    else:

        class Config:
            frozen = True
            smart_union = True
            extra = pydantic.Extra.allow
