"""Typed contracts for MCP response payload assembly."""

from __future__ import annotations

from typing import Any, Literal, TypedDict


class EvidenceException(TypedDict, total=False):
    type: str
    message: str


class EvidenceCrashFrame(TypedDict, total=False):
    index: int
    file_rel: str
    line: int
    function: str
    code: str


class EvidenceLocalSummary(TypedDict, total=False):
    name: str
    type: str
    preview: str


class EvidenceRepro(TypedDict, total=False):
    argv: list[Any]
    nodeid: str


class StableEvidencePayload(TypedDict, total=False):
    exception: EvidenceException
    crash_frame: EvidenceCrashFrame
    locals_summary: list[EvidenceLocalSummary]
    repro: EvidenceRepro
    evidence_ids: list[str]
    sections: list[dict[str, Any]]
    summary: str


class MCPErrorPayload(TypedDict, total=False):
    code: str
    message: str
    details: dict[str, Any]


class MCPResponsePayload(TypedDict, total=False):
    tool: str
    format_version: str
    evidence: dict[str, Any]
    metadata: MCPMetadataPayload
    rca: dict[str, Any]
    error: MCPErrorPayload


class MCPMetadataPayload(TypedDict, total=False):
    response_format: str
    with_rca: bool
    evidence_schema: str
    status: Literal["ok", "error"]


__all__ = [
    "EvidenceCrashFrame",
    "EvidenceException",
    "EvidenceLocalSummary",
    "EvidenceRepro",
    "MCPErrorPayload",
    "MCPMetadataPayload",
    "MCPResponsePayload",
    "StableEvidencePayload",
]
