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

from __future__ import annotations
from .toolstatuserror import ToolStatusError, ToolStatusErrorTypedDict
from .toolstatusfile import ToolStatusFile, ToolStatusFileTypedDict
from .toolstatusparameter import ToolStatusParameter, ToolStatusParameterTypedDict
from friendli.core.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from pydantic import model_serializer
from typing import List, Literal
from typing_extensions import NotRequired, TypedDict

Name = Literal[
    "linkup:search",
    "math:calculator",
    "math:statistics",
    "math:calendar",
    "web:search",
    "web:url",
    "code:python-interpreter",
    "file:text",
]
"The name of the built-in tool."
Status = Literal["STARTED", "UPDATING", "ENDED", "ERRORED"]
"Indicates the current execution status of the tool."


class ToolStatusDataTypedDict(TypedDict):
    tool_call_id: str
    "The ID of the tool call."
    name: Name
    "The name of the built-in tool."
    status: Status
    "Indicates the current execution status of the tool."
    parameters: List[ToolStatusParameterTypedDict]
    timestamp: float
    "The Unix timestamp (in seconds) for when the event occurred."
    result: NotRequired[Nullable[str]]
    "The output from the tool's execution."
    files: NotRequired[Nullable[List[ToolStatusFileTypedDict]]]
    message: NotRequired[Nullable[str]]
    "Message generated by the tool's execution."
    error: NotRequired[Nullable[ToolStatusErrorTypedDict]]


class ToolStatusData(BaseModel):
    tool_call_id: str
    "The ID of the tool call."
    name: Name
    "The name of the built-in tool."
    status: Status
    "Indicates the current execution status of the tool."
    parameters: List[ToolStatusParameter]
    timestamp: float
    "The Unix timestamp (in seconds) for when the event occurred."
    result: OptionalNullable[str] = UNSET
    "The output from the tool's execution."
    files: OptionalNullable[List[ToolStatusFile]] = UNSET
    message: OptionalNullable[str] = UNSET
    "Message generated by the tool's execution."
    error: OptionalNullable[ToolStatusError] = UNSET

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["result", "files", "message", "error"]
        nullable_fields = ["result", "files", "message", "error"]
        null_default_fields = []
        serialized = handler(self)
        m = {}
        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            serialized.pop(k, None)
            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )
            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                k not in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val
        return m
