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

import datetime as dt
import typing

import pydantic
from ..core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
from .comment import Comment
from .error_info import ErrorInfo
from .feedback_score import FeedbackScore
from .guardrails_validation import GuardrailsValidation
from .json_list_string import JsonListString
from .trace_visibility_mode import TraceVisibilityMode


class Trace(UniversalBaseModel):
    id: typing.Optional[str] = None
    project_name: typing.Optional[str] = pydantic.Field(default=None)
    """
    If null, the default project is used
    """

    project_id: typing.Optional[str] = None
    name: typing.Optional[str] = None
    start_time: dt.datetime
    end_time: typing.Optional[dt.datetime] = None
    input: typing.Optional[JsonListString] = None
    output: typing.Optional[JsonListString] = None
    metadata: typing.Optional[JsonListString] = None
    tags: typing.Optional[typing.List[str]] = None
    error_info: typing.Optional[ErrorInfo] = None
    usage: typing.Optional[typing.Dict[str, int]] = None
    created_at: typing.Optional[dt.datetime] = None
    last_updated_at: typing.Optional[dt.datetime] = None
    created_by: typing.Optional[str] = None
    last_updated_by: typing.Optional[str] = None
    feedback_scores: typing.Optional[typing.List[FeedbackScore]] = None
    span_feedback_scores: typing.Optional[typing.List[FeedbackScore]] = pydantic.Field(default=None)
    """
    Aggregated feedback scores from all spans in this trace, averaged by score name
    """

    comments: typing.Optional[typing.List[Comment]] = None
    guardrails_validations: typing.Optional[typing.List[GuardrailsValidation]] = None
    total_estimated_cost: typing.Optional[float] = None
    span_count: typing.Optional[int] = None
    duration: typing.Optional[float] = pydantic.Field(default=None)
    """
    Duration in milliseconds as a decimal number to support sub-millisecond precision
    """

    thread_id: typing.Optional[str] = None
    visibility_mode: typing.Optional[TraceVisibilityMode] = None
    llm_span_count: typing.Optional[int] = None
    has_tool_spans: typing.Optional[bool] = None
    providers: typing.Optional[typing.List[str]] = pydantic.Field(default=None)
    """
    List of unique provider names from all spans in this trace, sorted alphabetically
    """

    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
