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

from __future__ import annotations
from .fusionanalysisresult import FusionAnalysisResult, FusionAnalysisResultTypedDict
from .toolcallstatus import ToolCallStatus
from openrouter.types import BaseModel
from openrouter.utils import validate_open_enum
from pydantic.functional_validators import PlainValidator
from typing import List, Literal, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class FailedModelTypedDict(TypedDict):
    error: str
    r"""Error message describing why the model failed."""
    model: str
    r"""Slug of the analysis model that failed."""
    status_code: NotRequired[int]
    r"""HTTP status code from the upstream response, when available (e.g. 402, 429)."""


class FailedModel(BaseModel):
    error: str
    r"""Error message describing why the model failed."""

    model: str
    r"""Slug of the analysis model that failed."""

    status_code: Optional[int] = None
    r"""HTTP status code from the upstream response, when available (e.g. 402, 429)."""


class ResponseTypedDict(TypedDict):
    model: str
    content: NotRequired[str]


class Response(BaseModel):
    model: str

    content: Optional[str] = None


OutputFusionServerToolItemType = Literal["openrouter:fusion",]


class OutputFusionServerToolItemTypedDict(TypedDict):
    r"""An openrouter:fusion server tool output item"""

    status: ToolCallStatus
    type: OutputFusionServerToolItemType
    analysis: NotRequired[FusionAnalysisResultTypedDict]
    r"""Structured analysis produced by the fusion judge model."""
    error: NotRequired[str]
    r"""Error message when the fusion run did not produce an analysis result."""
    failed_models: NotRequired[List[FailedModelTypedDict]]
    r"""Models that were requested as part of the analysis panel but did not produce a response. Present when at least one requested analysis model failed. The fusion result is still usable but was produced from a degraded panel."""
    failure_reason: NotRequired[str]
    r"""Typed failure reason when the fusion run failed. Possible values include: all_panels_failed, insufficient_credits, rate_limited, judge_not_valid_json, judge_schema_mismatch, judge_upstream_error, judge_empty_completion."""
    id: NotRequired[str]
    responses: NotRequired[List[ResponseTypedDict]]
    r"""Analysis models that produced a response in this fusion run, with each model's full panel content."""


class OutputFusionServerToolItem(BaseModel):
    r"""An openrouter:fusion server tool output item"""

    status: Annotated[ToolCallStatus, PlainValidator(validate_open_enum(False))]

    type: OutputFusionServerToolItemType

    analysis: Optional[FusionAnalysisResult] = None
    r"""Structured analysis produced by the fusion judge model."""

    error: Optional[str] = None
    r"""Error message when the fusion run did not produce an analysis result."""

    failed_models: Optional[List[FailedModel]] = None
    r"""Models that were requested as part of the analysis panel but did not produce a response. Present when at least one requested analysis model failed. The fusion result is still usable but was produced from a degraded panel."""

    failure_reason: Optional[str] = None
    r"""Typed failure reason when the fusion run failed. Possible values include: all_panels_failed, insufficient_credits, rate_limited, judge_not_valid_json, judge_schema_mismatch, judge_upstream_error, judge_empty_completion."""

    id: Optional[str] = None

    responses: Optional[List[Response]] = None
    r"""Analysis models that produced a response in this fusion run, with each model's full panel content."""
