# 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 .environment import Environment, EnvironmentParam
from .generationconfig import GenerationConfig, GenerationConfigParam
from .interactionsinput import InteractionsInput, InteractionsInputParam
from .model import Model
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 model_serializer
from typing import Dict, List, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


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


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


CreateModelInteractionEnvironmentParam = TypeAliasType(
    "CreateModelInteractionEnvironmentParam", 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."""


CreateModelInteractionEnvironment = TypeAliasType(
    "CreateModelInteractionEnvironment", 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."""


class CreateModelInteractionParam(TypedDict):
    r"""Parameters for creating model interactions"""

    model: Model
    r"""The model that will complete your prompt.\n\nSee [models](https://ai.google.dev/gemini-api/docs/models) for additional details."""
    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[CreateModelInteractionResponseFormatParam]
    r"""Enforces that the generated response is a JSON object that complies with the JSON schema specified in this field."""
    environment: NotRequired[CreateModelInteractionEnvironmentParam]
    r"""The environment configuration for the interaction. Can be an object specifying remote environment sources or a string referencing an existing environment ID."""
    generation_config: NotRequired[GenerationConfigParam]
    r"""Configuration parameters for model interactions."""
    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 CreateModelInteraction(BaseModel):
    r"""Parameters for creating model interactions"""

    model: Model
    r"""The model that will complete your prompt.\n\nSee [models](https://ai.google.dev/gemini-api/docs/models) for additional details."""

    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[CreateModelInteractionResponseFormat] = None
    r"""Enforces that the generated response is a JSON object that complies with the JSON schema specified in this field."""

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

    generation_config: Optional[GenerationConfig] = None
    r"""Configuration parameters for model interactions."""

    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",
                "generation_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
