"""
OpenResponses types for evaluatorq.

These types represent the OpenResponses format, an industry standard for
representing LLM agent interactions including messages, function calls,
and their outputs.
"""

from __future__ import annotations

from typing import Any

from typing_extensions import TypedDict


class OutputTextContent(TypedDict, total=False):
    """Output text content from the model."""

    type: str  # Always "output_text"
    text: str
    annotations: list[Any]
    logprobs: list[Any]


class FunctionCallDict(TypedDict, total=False):
    """A function tool call that was generated by the model."""

    type: str  # Always "function_call"
    id: str
    call_id: str
    name: str
    arguments: str
    status: str


class FunctionCallOutputDict(TypedDict, total=False):
    """A function tool call output that was returned by the tool."""

    type: str  # Always "function_call_output"
    id: str
    call_id: str
    output: str
    status: str


class MessageDict(TypedDict, total=False):
    """A message to or from the model."""

    type: str  # Always "message"
    id: str
    status: str
    role: str
    content: list[dict[str, Any]]


class UsageDict(TypedDict, total=False):
    """Token usage information."""

    input_tokens: int
    output_tokens: int
    total_tokens: int
    input_tokens_details: dict[str, int]
    output_tokens_details: dict[str, int]


class TextFieldDict(TypedDict, total=False):
    """Text format configuration."""

    format: dict[str, str]
    verbosity: str | None


class ResponseResourceDict(TypedDict, total=False):
    """
    The complete response object in OpenResponses format.

    This represents the industry standard format for representing
    LLM agent interactions.
    """

    id: str
    object: str  # Always "response"
    created_at: int
    completed_at: int | None
    status: str
    incomplete_details: dict[str, Any] | None
    model: str
    previous_response_id: str | None
    instructions: str | None
    input: list[dict[str, Any]]
    output: list[dict[str, Any]]
    error: dict[str, Any] | None
    tools: list[dict[str, Any]]
    tool_choice: str
    truncation: str
    parallel_tool_calls: bool
    text: dict[str, Any]
    top_p: float
    presence_penalty: float
    frequency_penalty: float
    top_logprobs: int
    temperature: float
    reasoning: dict[str, Any] | None
    usage: dict[str, Any] | None
    max_output_tokens: int | None
    max_tool_calls: int | None
    store: bool
    background: bool
    service_tier: str
    metadata: dict[str, Any]
    safety_identifier: str | None
    prompt_cache_key: str | None


# Type aliases for convenience
FunctionCall = FunctionCallDict
FunctionCallOutput = FunctionCallOutputDict
Message = MessageDict
ResponseResource = ResponseResourceDict
Usage = UsageDict
TextField = TextFieldDict


__all__ = [
    "FunctionCall",
    "FunctionCallDict",
    "FunctionCallOutput",
    "FunctionCallOutputDict",
    "Message",
    "MessageDict",
    "OutputTextContent",
    "ResponseResource",
    "ResponseResourceDict",
    "TextField",
    "TextFieldDict",
    "Usage",
    "UsageDict",
]
