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

from __future__ import annotations
from .openairesponsesrefusalcontent import (
    OpenAIResponsesRefusalContent,
    OpenAIResponsesRefusalContentTypedDict,
)
from .openresponseseasyinputmessage import (
    OpenResponsesEasyInputMessage,
    OpenResponsesEasyInputMessageTypedDict,
)
from .openresponsesfunctioncalloutput import (
    OpenResponsesFunctionCallOutput,
    OpenResponsesFunctionCallOutputTypedDict,
)
from .openresponsesfunctiontoolcall import (
    OpenResponsesFunctionToolCall,
    OpenResponsesFunctionToolCallTypedDict,
)
from .openresponsesinputmessageitem import (
    OpenResponsesInputMessageItem,
    OpenResponsesInputMessageItemTypedDict,
)
from .openresponsesreasoning import (
    OpenResponsesReasoning,
    OpenResponsesReasoningTypedDict,
)
from .reasoningsummarytext import ReasoningSummaryText, ReasoningSummaryTextTypedDict
from .reasoningtextcontent import ReasoningTextContent, ReasoningTextContentTypedDict
from .responseoutputtext import ResponseOutputText, ResponseOutputTextTypedDict
from .responsesimagegenerationcall import (
    ResponsesImageGenerationCall,
    ResponsesImageGenerationCallTypedDict,
)
from .responsesoutputitemfilesearchcall import (
    ResponsesOutputItemFileSearchCall,
    ResponsesOutputItemFileSearchCallTypedDict,
)
from .responsesoutputitemfunctioncall import (
    ResponsesOutputItemFunctionCall,
    ResponsesOutputItemFunctionCallTypedDict,
)
from .responseswebsearchcalloutput import (
    ResponsesWebSearchCallOutput,
    ResponsesWebSearchCallOutputTypedDict,
)
from openrouter.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
    UnrecognizedStr,
)
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


OpenResponsesInputTypeReasoning = Literal["reasoning",]


OpenResponsesInputStatusInProgress2 = Literal["in_progress",]


OpenResponsesInputStatusIncomplete2 = Literal["incomplete",]


OpenResponsesInputStatusCompleted2 = Literal["completed",]


OpenResponsesInputStatusUnion2TypedDict = TypeAliasType(
    "OpenResponsesInputStatusUnion2TypedDict",
    Union[
        OpenResponsesInputStatusCompleted2,
        OpenResponsesInputStatusIncomplete2,
        OpenResponsesInputStatusInProgress2,
    ],
)


OpenResponsesInputStatusUnion2 = TypeAliasType(
    "OpenResponsesInputStatusUnion2",
    Union[
        OpenResponsesInputStatusCompleted2,
        OpenResponsesInputStatusIncomplete2,
        OpenResponsesInputStatusInProgress2,
    ],
)


OpenResponsesInputFormat = Union[
    Literal[
        "unknown",
        "openai-responses-v1",
        "azure-openai-responses-v1",
        "xai-responses-v1",
        "anthropic-claude-v1",
        "google-gemini-v1",
    ],
    UnrecognizedStr,
]
r"""The format of the reasoning content"""


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

    type: OpenResponsesInputTypeReasoning
    id: str
    summary: Nullable[List[ReasoningSummaryTextTypedDict]]
    content: NotRequired[Nullable[List[ReasoningTextContentTypedDict]]]
    encrypted_content: NotRequired[Nullable[str]]
    status: NotRequired[OpenResponsesInputStatusUnion2TypedDict]
    signature: NotRequired[Nullable[str]]
    r"""A signature for the reasoning content, used for verification"""
    format_: NotRequired[Nullable[OpenResponsesInputFormat]]
    r"""The format of the reasoning content"""


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

    type: OpenResponsesInputTypeReasoning

    id: str

    summary: Nullable[List[ReasoningSummaryText]]

    content: OptionalNullable[List[ReasoningTextContent]] = UNSET

    encrypted_content: OptionalNullable[str] = UNSET

    status: Optional[OpenResponsesInputStatusUnion2] = None

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

    format_: Annotated[
        Annotated[
            OptionalNullable[OpenResponsesInputFormat],
            PlainValidator(validate_open_enum(False)),
        ],
        pydantic.Field(alias="format"),
    ] = UNSET
    r"""The format of the reasoning content"""

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


OpenResponsesInputRole = Literal["assistant",]


OpenResponsesInputTypeMessage = Literal["message",]


OpenResponsesInputStatusInProgress1 = Literal["in_progress",]


OpenResponsesInputStatusIncomplete1 = Literal["incomplete",]


OpenResponsesInputStatusCompleted1 = Literal["completed",]


OpenResponsesInputStatusUnion1TypedDict = TypeAliasType(
    "OpenResponsesInputStatusUnion1TypedDict",
    Union[
        OpenResponsesInputStatusCompleted1,
        OpenResponsesInputStatusIncomplete1,
        OpenResponsesInputStatusInProgress1,
    ],
)


OpenResponsesInputStatusUnion1 = TypeAliasType(
    "OpenResponsesInputStatusUnion1",
    Union[
        OpenResponsesInputStatusCompleted1,
        OpenResponsesInputStatusIncomplete1,
        OpenResponsesInputStatusInProgress1,
    ],
)


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


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


OpenResponsesInputContent2TypedDict = TypeAliasType(
    "OpenResponsesInputContent2TypedDict",
    Union[List[OpenResponsesInputContent1TypedDict], str, Any],
)


OpenResponsesInputContent2 = TypeAliasType(
    "OpenResponsesInputContent2", Union[List[OpenResponsesInputContent1], str, Any]
)


OpenResponsesInputPhaseFinalAnswer = Literal["final_answer",]


OpenResponsesInputPhaseCommentary = Literal["commentary",]


OpenResponsesInputPhaseUnionTypedDict = TypeAliasType(
    "OpenResponsesInputPhaseUnionTypedDict",
    Union[OpenResponsesInputPhaseCommentary, OpenResponsesInputPhaseFinalAnswer, 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."""


OpenResponsesInputPhaseUnion = TypeAliasType(
    "OpenResponsesInputPhaseUnion",
    Union[OpenResponsesInputPhaseCommentary, OpenResponsesInputPhaseFinalAnswer, 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."""


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

    id: str
    role: OpenResponsesInputRole
    type: OpenResponsesInputTypeMessage
    content: Nullable[OpenResponsesInputContent2TypedDict]
    status: NotRequired[OpenResponsesInputStatusUnion1TypedDict]
    phase: NotRequired[Nullable[OpenResponsesInputPhaseUnionTypedDict]]
    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."""


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

    id: str

    role: OpenResponsesInputRole

    type: OpenResponsesInputTypeMessage

    content: Nullable[OpenResponsesInputContent2]

    status: Optional[OpenResponsesInputStatusUnion1] = None

    phase: OptionalNullable[OpenResponsesInputPhaseUnion] = 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."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["status", "phase"]
        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


OpenResponsesInputUnion1TypedDict = TypeAliasType(
    "OpenResponsesInputUnion1TypedDict",
    Union[
        OpenResponsesEasyInputMessageTypedDict,
        OpenResponsesInputMessageItemTypedDict,
        ResponsesWebSearchCallOutputTypedDict,
        ResponsesOutputItemFileSearchCallTypedDict,
        ResponsesImageGenerationCallTypedDict,
        OpenResponsesFunctionCallOutputTypedDict,
        OpenResponsesFunctionToolCallTypedDict,
        OpenResponsesInputMessageTypedDict,
        ResponsesOutputItemFunctionCallTypedDict,
        OpenResponsesReasoningTypedDict,
        OpenResponsesInputReasoningTypedDict,
    ],
)


OpenResponsesInputUnion1 = TypeAliasType(
    "OpenResponsesInputUnion1",
    Union[
        OpenResponsesEasyInputMessage,
        OpenResponsesInputMessageItem,
        ResponsesWebSearchCallOutput,
        ResponsesOutputItemFileSearchCall,
        ResponsesImageGenerationCall,
        OpenResponsesFunctionCallOutput,
        OpenResponsesFunctionToolCall,
        OpenResponsesInputMessage,
        ResponsesOutputItemFunctionCall,
        OpenResponsesReasoning,
        OpenResponsesInputReasoning,
    ],
)


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


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