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

from __future__ import annotations
from openrouter.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
    UnrecognizedStr,
)
from openrouter.utils import validate_open_enum
import pydantic
from pydantic import ConfigDict, model_serializer
from pydantic.functional_validators import PlainValidator
from typing import Any, Dict, List, Literal, Union
from typing_extensions import Annotated, NotRequired, TypedDict


class ShellCallOutputItemOutputTypedDict(TypedDict):
    type: str
    content: NotRequired[Nullable[str]]
    exit_code: NotRequired[Nullable[int]]


class ShellCallOutputItemOutput(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True, arbitrary_types_allowed=True, extra="allow"
    )
    __pydantic_extra__: Dict[str, Nullable[Any]] = pydantic.Field(init=False)

    type: str

    content: OptionalNullable[str] = UNSET

    exit_code: OptionalNullable[int] = UNSET

    @property
    def additional_properties(self):
        return self.__pydantic_extra__

    @additional_properties.setter
    def additional_properties(self, value):
        self.__pydantic_extra__ = value  # pyright: ignore[reportIncompatibleVariableOverride]

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

        for k, v in serialized.items():
            m[k] = v

        return m


ShellCallOutputItemStatus = Union[
    Literal[
        "in_progress",
        "completed",
        "incomplete",
    ],
    UnrecognizedStr,
]


ShellCallOutputItemType = Literal["shell_call_output",]


class ShellCallOutputItemTypedDict(TypedDict):
    r"""Output from a shell command execution (newer variant)"""

    call_id: str
    output: List[ShellCallOutputItemOutputTypedDict]
    type: ShellCallOutputItemType
    id: NotRequired[Nullable[str]]
    max_output_length: NotRequired[Nullable[int]]
    status: NotRequired[Nullable[ShellCallOutputItemStatus]]


class ShellCallOutputItem(BaseModel):
    r"""Output from a shell command execution (newer variant)"""

    call_id: str

    output: List[ShellCallOutputItemOutput]

    type: ShellCallOutputItemType

    id: OptionalNullable[str] = UNSET

    max_output_length: OptionalNullable[int] = UNSET

    status: Annotated[
        OptionalNullable[ShellCallOutputItemStatus],
        PlainValidator(validate_open_enum(False)),
    ] = UNSET

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