# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# pyformat: disable

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

from __future__ import annotations
from .. import BaseModel, UNSET_SENTINEL
from .agentoption import AgentOption
from .antigravityagentconfig import AntigravityAgentConfig, AntigravityAgentConfigParam
from .codemenderagentconfig import CodeMenderAgentConfig, CodeMenderAgentConfigParam
from .deepresearchagentconfig import (
    DeepResearchAgentConfig,
    DeepResearchAgentConfigParam,
)
from .dynamicagentconfig import DynamicAgentConfig, DynamicAgentConfigParam
from .environment import Environment, EnvironmentParam
from .interactionsinput import InteractionsInput, InteractionsInputParam
from .responseformat import ResponseFormat, ResponseFormatParam
from .responsemodality import ResponseModality
from .safetysetting import SafetySetting, SafetySettingParam
from .servicetier import ServiceTier
from .tool import Tool, ToolParam
from .webhookconfig import WebhookConfig, WebhookConfigParam
import pydantic
from pydantic import Field, model_serializer
from typing import Dict, List, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


CreateAgentInteractionResponseFormatParam = TypeAliasType(
    "CreateAgentInteractionResponseFormatParam",
    Union[List[ResponseFormatParam], ResponseFormatParam],
)
r"""Enforces that the generated response is a JSON object that complies with the JSON schema specified in this field."""


CreateAgentInteractionResponseFormat = TypeAliasType(
    "CreateAgentInteractionResponseFormat", Union[List[ResponseFormat], ResponseFormat]
)
r"""Enforces that the generated response is a JSON object that complies with the JSON schema specified in this field."""


CreateAgentInteractionEnvironmentParam = TypeAliasType(
    "CreateAgentInteractionEnvironmentParam", Union[EnvironmentParam, str]
)
r"""The environment configuration for the interaction. Can be an object specifying remote environment sources or a string referencing an existing environment ID."""


CreateAgentInteractionEnvironment = TypeAliasType(
    "CreateAgentInteractionEnvironment", Union[Environment, str]
)
r"""The environment configuration for the interaction. Can be an object specifying remote environment sources or a string referencing an existing environment ID."""


CreateAgentInteractionAgentConfigParam = TypeAliasType(
    "CreateAgentInteractionAgentConfigParam",
    Union[
        DynamicAgentConfigParam,
        AntigravityAgentConfigParam,
        DeepResearchAgentConfigParam,
        CodeMenderAgentConfigParam,
    ],
)
r"""Configuration parameters for the agent interaction."""


CreateAgentInteractionAgentConfig = Annotated[
    Union[
        DynamicAgentConfig,
        DeepResearchAgentConfig,
        CodeMenderAgentConfig,
        AntigravityAgentConfig,
    ],
    Field(discriminator="type"),
]
r"""Configuration parameters for the agent interaction."""


class CreateAgentInteractionParam(TypedDict):
    r"""Parameters for creating agent interactions"""

    agent: AgentOption
    r"""The agent to interact with."""
    input: InteractionsInputParam
    r"""The input for the interaction."""
    stream: NotRequired[bool]
    r"""Input only. Whether the interaction will be streamed."""
    store: NotRequired[bool]
    r"""Input only. Whether to store the response and request for later retrieval."""
    background: NotRequired[bool]
    r"""Input only. Whether to run the model interaction in the background."""
    system_instruction: NotRequired[str]
    r"""System instruction for the interaction."""
    tools: NotRequired[List[ToolParam]]
    r"""A list of tool declarations the model may call during interaction."""
    response_modalities: NotRequired[List[ResponseModality]]
    r"""The requested modalities of the response (TEXT, IMAGE, AUDIO)."""
    response_mime_type: NotRequired[str]
    r"""The mime type of the response. This is required if response_format is set."""
    previous_interaction_id: NotRequired[str]
    r"""The ID of the previous interaction, if any."""
    service_tier: NotRequired[ServiceTier]
    webhook_config: NotRequired[WebhookConfigParam]
    r"""Message for configuring webhook events for a request."""
    response_format: NotRequired[CreateAgentInteractionResponseFormatParam]
    r"""Enforces that the generated response is a JSON object that complies with the JSON schema specified in this field."""
    environment: NotRequired[CreateAgentInteractionEnvironmentParam]
    r"""The environment configuration for the interaction. Can be an object specifying remote environment sources or a string referencing an existing environment ID."""
    agent_config: NotRequired[CreateAgentInteractionAgentConfigParam]
    r"""Configuration parameters for the agent interaction."""
    safety_settings: NotRequired[List[SafetySettingParam]]
    r"""Safety settings for the interaction."""
    labels: NotRequired[Dict[str, str]]
    r"""The labels with user-defined metadata for the request."""


class CreateAgentInteraction(BaseModel):
    r"""Parameters for creating agent interactions"""

    agent: AgentOption
    r"""The agent to interact with."""

    input: InteractionsInput
    r"""The input for the interaction."""

    stream: Optional[bool] = None
    r"""Input only. Whether the interaction will be streamed."""

    store: Optional[bool] = None
    r"""Input only. Whether to store the response and request for later retrieval."""

    background: Optional[bool] = None
    r"""Input only. Whether to run the model interaction in the background."""

    system_instruction: Optional[str] = None
    r"""System instruction for the interaction."""

    tools: Optional[List[Tool]] = None
    r"""A list of tool declarations the model may call during interaction."""

    response_modalities: Optional[List[ResponseModality]] = None
    r"""The requested modalities of the response (TEXT, IMAGE, AUDIO)."""

    response_mime_type: Annotated[
        Optional[str],
        pydantic.Field(
            deprecated="warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible."
        ),
    ] = None
    r"""The mime type of the response. This is required if response_format is set."""

    previous_interaction_id: Optional[str] = None
    r"""The ID of the previous interaction, if any."""

    service_tier: Optional[ServiceTier] = None

    webhook_config: Optional[WebhookConfig] = None
    r"""Message for configuring webhook events for a request."""

    response_format: Optional[CreateAgentInteractionResponseFormat] = None
    r"""Enforces that the generated response is a JSON object that complies with the JSON schema specified in this field."""

    environment: Optional[CreateAgentInteractionEnvironment] = None
    r"""The environment configuration for the interaction. Can be an object specifying remote environment sources or a string referencing an existing environment ID."""

    agent_config: Optional[CreateAgentInteractionAgentConfig] = None
    r"""Configuration parameters for the agent interaction."""

    safety_settings: Optional[List[SafetySetting]] = None
    r"""Safety settings for the interaction."""

    labels: Optional[Dict[str, str]] = None
    r"""The labels with user-defined metadata for the request."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "stream",
                "store",
                "background",
                "system_instruction",
                "tools",
                "response_modalities",
                "response_mime_type",
                "previous_interaction_id",
                "service_tier",
                "webhook_config",
                "response_format",
                "environment",
                "agent_config",
                "safety_settings",
                "labels",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m
