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

from __future__ import annotations
from .applypatchcallitem import ApplyPatchCallItem, ApplyPatchCallItemTypedDict
from .applypatchcalloutputitem import (
    ApplyPatchCallOutputItem,
    ApplyPatchCallOutputItemTypedDict,
)
from .compactionitem import CompactionItem, CompactionItemTypedDict
from .customtoolcallitem import CustomToolCallItem, CustomToolCallItemTypedDict
from .customtoolcalloutputitem import (
    CustomToolCallOutputItem,
    CustomToolCallOutputItemTypedDict,
)
from .easyinputmessage import EasyInputMessage, EasyInputMessageTypedDict
from .functioncallitem import FunctionCallItem, FunctionCallItemTypedDict
from .functioncalloutputitem import (
    FunctionCallOutputItem,
    FunctionCallOutputItemTypedDict,
)
from .inputmessageitem import InputMessageItem, InputMessageItemTypedDict
from .itemreferenceitem import ItemReferenceItem, ItemReferenceItemTypedDict
from .localshellcallitem import LocalShellCallItem, LocalShellCallItemTypedDict
from .localshellcalloutputitem import (
    LocalShellCallOutputItem,
    LocalShellCallOutputItemTypedDict,
)
from .mcpapprovalrequestitem import (
    McpApprovalRequestItem,
    McpApprovalRequestItemTypedDict,
)
from .mcpapprovalresponseitem import (
    McpApprovalResponseItem,
    McpApprovalResponseItemTypedDict,
)
from .mcpcallitem import McpCallItem, McpCallItemTypedDict
from .mcplisttoolsitem import McpListToolsItem, McpListToolsItemTypedDict
from .openairesponsesrefusalcontent import (
    OpenAIResponsesRefusalContent,
    OpenAIResponsesRefusalContentTypedDict,
)
from .outputadvisorservertoolitem import (
    OutputAdvisorServerToolItem,
    OutputAdvisorServerToolItemTypedDict,
)
from .outputapplypatchservertoolitem import (
    OutputApplyPatchServerToolItem,
    OutputApplyPatchServerToolItemTypedDict,
)
from .outputbashservertoolitem import (
    OutputBashServerToolItem,
    OutputBashServerToolItemTypedDict,
)
from .outputbrowseruseservertoolitem import (
    OutputBrowserUseServerToolItem,
    OutputBrowserUseServerToolItemTypedDict,
)
from .outputcodeinterpretercallitem import (
    OutputCodeInterpreterCallItem,
    OutputCodeInterpreterCallItemTypedDict,
)
from .outputcodeinterpreterservertoolitem import (
    OutputCodeInterpreterServerToolItem,
    OutputCodeInterpreterServerToolItemTypedDict,
)
from .outputcomputercallitem import (
    OutputComputerCallItem,
    OutputComputerCallItemTypedDict,
)
from .outputcustomtoolcallitem import (
    OutputCustomToolCallItem,
    OutputCustomToolCallItemTypedDict,
)
from .outputdatetimeitem import OutputDatetimeItem, OutputDatetimeItemTypedDict
from .outputfilesearchcallitem import (
    OutputFileSearchCallItem,
    OutputFileSearchCallItemTypedDict,
)
from .outputfilesearchservertoolitem import (
    OutputFileSearchServerToolItem,
    OutputFileSearchServerToolItemTypedDict,
)
from .outputfunctioncallitem import (
    OutputFunctionCallItem,
    OutputFunctionCallItemTypedDict,
)
from .outputfusionservertoolitem import (
    OutputFusionServerToolItem,
    OutputFusionServerToolItemTypedDict,
)
from .outputimagegenerationcallitem import (
    OutputImageGenerationCallItem,
    OutputImageGenerationCallItemTypedDict,
)
from .outputimagegenerationservertoolitem import (
    OutputImageGenerationServerToolItem,
    OutputImageGenerationServerToolItemTypedDict,
)
from .outputmcpservertoolitem import (
    OutputMcpServerToolItem,
    OutputMcpServerToolItemTypedDict,
)
from .outputmemoryservertoolitem import (
    OutputMemoryServerToolItem,
    OutputMemoryServerToolItemTypedDict,
)
from .outputsearchmodelsservertoolitem import (
    OutputSearchModelsServerToolItem,
    OutputSearchModelsServerToolItemTypedDict,
)
from .outputsubagentservertoolitem import (
    OutputSubagentServerToolItem,
    OutputSubagentServerToolItemTypedDict,
)
from .outputtexteditorservertoolitem import (
    OutputTextEditorServerToolItem,
    OutputTextEditorServerToolItemTypedDict,
)
from .outputtoolsearchservertoolitem import (
    OutputToolSearchServerToolItem,
    OutputToolSearchServerToolItemTypedDict,
)
from .outputwebfetchservertoolitem import (
    OutputWebFetchServerToolItem,
    OutputWebFetchServerToolItemTypedDict,
)
from .outputwebsearchcallitem import (
    OutputWebSearchCallItem,
    OutputWebSearchCallItemTypedDict,
)
from .outputwebsearchservertoolitem import (
    OutputWebSearchServerToolItem,
    OutputWebSearchServerToolItemTypedDict,
)
from .reasoningformat import ReasoningFormat
from .reasoningitem import ReasoningItem, ReasoningItemTypedDict
from .reasoningsummarytext import ReasoningSummaryText, ReasoningSummaryTextTypedDict
from .reasoningtextcontent import ReasoningTextContent, ReasoningTextContentTypedDict
from .responseoutputtext import ResponseOutputText, ResponseOutputTextTypedDict
from .shellcallitem import ShellCallItem, ShellCallItemTypedDict
from .shellcalloutputitem import ShellCallOutputItem, ShellCallOutputItemTypedDict
from openrouter.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from openrouter.utils import get_discriminator, validate_open_enum
import pydantic
from pydantic import Discriminator, Tag, model_serializer
from pydantic.functional_validators import PlainValidator
from typing import Any, List, Literal, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


InputsStatusInProgress2 = Literal["in_progress",]


InputsStatusIncomplete2 = Literal["incomplete",]


InputsStatusCompleted2 = Literal["completed",]


InputsStatusUnion2TypedDict = TypeAliasType(
    "InputsStatusUnion2TypedDict",
    Union[InputsStatusCompleted2, InputsStatusIncomplete2, InputsStatusInProgress2],
)


InputsStatusUnion2 = TypeAliasType(
    "InputsStatusUnion2",
    Union[InputsStatusCompleted2, InputsStatusIncomplete2, InputsStatusInProgress2],
)


InputsTypeReasoning = Literal["reasoning",]


class InputsReasoningTypedDict(TypedDict):
    r"""An output item containing reasoning"""

    id: str
    summary: Nullable[List[ReasoningSummaryTextTypedDict]]
    type: InputsTypeReasoning
    content: NotRequired[Nullable[List[ReasoningTextContentTypedDict]]]
    encrypted_content: NotRequired[Nullable[str]]
    status: NotRequired[InputsStatusUnion2TypedDict]
    format_: NotRequired[Nullable[ReasoningFormat]]
    signature: NotRequired[Nullable[str]]
    r"""A signature for the reasoning content, used for verification"""


class InputsReasoning(BaseModel):
    r"""An output item containing reasoning"""

    id: str

    summary: Nullable[List[ReasoningSummaryText]]

    type: InputsTypeReasoning

    content: OptionalNullable[List[ReasoningTextContent]] = UNSET

    encrypted_content: OptionalNullable[str] = UNSET

    status: Optional[InputsStatusUnion2] = None

    format_: Annotated[
        Annotated[
            OptionalNullable[ReasoningFormat], PlainValidator(validate_open_enum(False))
        ],
        pydantic.Field(alias="format"),
    ] = UNSET

    signature: OptionalNullable[str] = UNSET
    r"""A signature for the reasoning content, used for verification"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "content",
            "encrypted_content",
            "status",
            "format",
            "signature",
        ]
        nullable_fields = [
            "content",
            "encrypted_content",
            "summary",
            "format",
            "signature",
        ]
        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
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m


InputsContent1TypedDict = TypeAliasType(
    "InputsContent1TypedDict",
    Union[OpenAIResponsesRefusalContentTypedDict, ResponseOutputTextTypedDict],
)


InputsContent1 = Annotated[
    Union[
        Annotated[ResponseOutputText, Tag("output_text")],
        Annotated[OpenAIResponsesRefusalContent, Tag("refusal")],
    ],
    Discriminator(lambda m: get_discriminator(m, "type", "type")),
]


InputsContent2TypedDict = TypeAliasType(
    "InputsContent2TypedDict", Union[List[InputsContent1TypedDict], str, Any]
)


InputsContent2 = TypeAliasType("InputsContent2", Union[List[InputsContent1], str, Any])


InputsPhaseFinalAnswer = Literal["final_answer",]


InputsPhaseCommentary = Literal["commentary",]


InputsPhaseUnionTypedDict = TypeAliasType(
    "InputsPhaseUnionTypedDict",
    Union[InputsPhaseCommentary, InputsPhaseFinalAnswer, Any],
)
r"""The phase of an assistant message. Use `commentary` for an intermediate assistant message and `final_answer` for the final assistant message. For follow-up requests with models like `gpt-5.3-codex` and later, preserve and resend phase on all assistant messages. Omitting it can degrade performance. Not used for user messages."""


InputsPhaseUnion = TypeAliasType(
    "InputsPhaseUnion", Union[InputsPhaseCommentary, InputsPhaseFinalAnswer, Any]
)
r"""The phase of an assistant message. Use `commentary` for an intermediate assistant message and `final_answer` for the final assistant message. For follow-up requests with models like `gpt-5.3-codex` and later, preserve and resend phase on all assistant messages. Omitting it can degrade performance. Not used for user messages."""


InputsRole = Literal["assistant",]


InputsStatusInProgress1 = Literal["in_progress",]


InputsStatusIncomplete1 = Literal["incomplete",]


InputsStatusCompleted1 = Literal["completed",]


InputsStatusUnion1TypedDict = TypeAliasType(
    "InputsStatusUnion1TypedDict",
    Union[InputsStatusCompleted1, InputsStatusIncomplete1, InputsStatusInProgress1],
)


InputsStatusUnion1 = TypeAliasType(
    "InputsStatusUnion1",
    Union[InputsStatusCompleted1, InputsStatusIncomplete1, InputsStatusInProgress1],
)


InputsTypeMessage = Literal["message",]


class InputsMessageTypedDict(TypedDict):
    r"""An output message item"""

    content: Nullable[InputsContent2TypedDict]
    id: str
    role: InputsRole
    type: InputsTypeMessage
    phase: NotRequired[Nullable[InputsPhaseUnionTypedDict]]
    r"""The phase of an assistant message. Use `commentary` for an intermediate assistant message and `final_answer` for the final assistant message. For follow-up requests with models like `gpt-5.3-codex` and later, preserve and resend phase on all assistant messages. Omitting it can degrade performance. Not used for user messages."""
    status: NotRequired[InputsStatusUnion1TypedDict]


class InputsMessage(BaseModel):
    r"""An output message item"""

    content: Nullable[InputsContent2]

    id: str

    role: InputsRole

    type: InputsTypeMessage

    phase: OptionalNullable[InputsPhaseUnion] = UNSET
    r"""The phase of an assistant message. Use `commentary` for an intermediate assistant message and `final_answer` for the final assistant message. For follow-up requests with models like `gpt-5.3-codex` and later, preserve and resend phase on all assistant messages. Omitting it can degrade performance. Not used for user messages."""

    status: Optional[InputsStatusUnion1] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["phase", "status"]
        nullable_fields = ["content", "phase"]
        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
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m


InputsUnion1TypedDict = TypeAliasType(
    "InputsUnion1TypedDict",
    Union[
        ItemReferenceItemTypedDict,
        CompactionItemTypedDict,
        OutputFileSearchCallItemTypedDict,
        EasyInputMessageTypedDict,
        InputMessageItemTypedDict,
        CustomToolCallOutputItemTypedDict,
        LocalShellCallOutputItemTypedDict,
        OutputToolSearchServerToolItemTypedDict,
        OutputFileSearchServerToolItemTypedDict,
        OutputWebSearchServerToolItemTypedDict,
        OutputImageGenerationCallItemTypedDict,
        OutputWebSearchCallItemTypedDict,
        LocalShellCallItemTypedDict,
        OutputSearchModelsServerToolItemTypedDict,
        FunctionCallOutputItemTypedDict,
        ApplyPatchCallItemTypedDict,
        OutputDatetimeItemTypedDict,
        McpApprovalResponseItemTypedDict,
        McpApprovalRequestItemTypedDict,
        McpListToolsItemTypedDict,
        ApplyPatchCallOutputItemTypedDict,
        OutputBrowserUseServerToolItemTypedDict,
        OutputMcpServerToolItemTypedDict,
        OutputTextEditorServerToolItemTypedDict,
        OutputApplyPatchServerToolItemTypedDict,
        ShellCallItemTypedDict,
        InputsMessageTypedDict,
        OutputMemoryServerToolItemTypedDict,
        OutputCodeInterpreterCallItemTypedDict,
        OutputCustomToolCallItemTypedDict,
        OutputComputerCallItemTypedDict,
        CustomToolCallItemTypedDict,
        ShellCallOutputItemTypedDict,
        McpCallItemTypedDict,
        OutputImageGenerationServerToolItemTypedDict,
        OutputFunctionCallItemTypedDict,
        OutputBashServerToolItemTypedDict,
        FunctionCallItemTypedDict,
        ReasoningItemTypedDict,
        OutputSubagentServerToolItemTypedDict,
        InputsReasoningTypedDict,
        OutputCodeInterpreterServerToolItemTypedDict,
        OutputWebFetchServerToolItemTypedDict,
        OutputAdvisorServerToolItemTypedDict,
        OutputFusionServerToolItemTypedDict,
    ],
)


InputsUnion1 = TypeAliasType(
    "InputsUnion1",
    Union[
        ItemReferenceItem,
        CompactionItem,
        OutputFileSearchCallItem,
        EasyInputMessage,
        InputMessageItem,
        CustomToolCallOutputItem,
        LocalShellCallOutputItem,
        OutputToolSearchServerToolItem,
        OutputFileSearchServerToolItem,
        OutputWebSearchServerToolItem,
        OutputImageGenerationCallItem,
        OutputWebSearchCallItem,
        LocalShellCallItem,
        OutputSearchModelsServerToolItem,
        FunctionCallOutputItem,
        ApplyPatchCallItem,
        OutputDatetimeItem,
        McpApprovalResponseItem,
        McpApprovalRequestItem,
        McpListToolsItem,
        ApplyPatchCallOutputItem,
        OutputBrowserUseServerToolItem,
        OutputMcpServerToolItem,
        OutputTextEditorServerToolItem,
        OutputApplyPatchServerToolItem,
        ShellCallItem,
        InputsMessage,
        OutputMemoryServerToolItem,
        OutputCodeInterpreterCallItem,
        OutputCustomToolCallItem,
        OutputComputerCallItem,
        CustomToolCallItem,
        ShellCallOutputItem,
        McpCallItem,
        OutputImageGenerationServerToolItem,
        OutputFunctionCallItem,
        OutputBashServerToolItem,
        FunctionCallItem,
        ReasoningItem,
        OutputSubagentServerToolItem,
        InputsReasoning,
        OutputCodeInterpreterServerToolItem,
        OutputWebFetchServerToolItem,
        OutputAdvisorServerToolItem,
        OutputFusionServerToolItem,
    ],
)


InputsUnionTypedDict = TypeAliasType(
    "InputsUnionTypedDict", Union[str, List[InputsUnion1TypedDict]]
)
r"""Input for a response request - can be a string or array of items"""


InputsUnion = TypeAliasType("InputsUnion", Union[str, List[InputsUnion1]])
r"""Input for a response request - can be a string or array of items"""
