# 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 ..interactions import (
    createagentinteraction as interactions_createagentinteraction,
    createmodelinteraction as interactions_createmodelinteraction,
)
from pydantic import model_serializer
from typing import Optional, Union
from typing_extensions import NotRequired, TypeAliasType, TypedDict


InteractionParam = TypeAliasType(
    "InteractionParam",
    Union[
        interactions_createagentinteraction.CreateAgentInteractionParam,
        interactions_createmodelinteraction.CreateModelInteractionParam,
    ],
)
r"""Required. The interaction request template to be executed."""


Interaction = TypeAliasType(
    "Interaction",
    Union[
        interactions_createagentinteraction.CreateAgentInteraction,
        interactions_createmodelinteraction.CreateModelInteraction,
    ],
)
r"""Required. The interaction request template to be executed."""


class TriggerCreateParamsParam(TypedDict):
    r"""Parameters for creating a trigger."""

    schedule: str
    r"""Required. The cron schedule on which the trigger should run. Standard cron format."""
    time_zone: str
    r"""Required. Time zone in which the schedule should be interpreted."""
    interaction: InteractionParam
    r"""Required. The interaction request template to be executed."""
    display_name: NotRequired[str]
    r"""Optional. The display name of the trigger."""
    environment_id: NotRequired[str]
    r"""Optional. The environment ID for the trigger execution."""
    max_consecutive_failures: NotRequired[int]
    r"""Optional. The maximum number of consecutive failures allowed before the trigger is automatically paused (status becomes ERROR)."""
    execution_timeout_seconds: NotRequired[int]
    r"""Optional. The execution timeout for the triggered interaction."""


class TriggerCreateParams(BaseModel):
    r"""Parameters for creating a trigger."""

    schedule: str
    r"""Required. The cron schedule on which the trigger should run. Standard cron format."""

    time_zone: str
    r"""Required. Time zone in which the schedule should be interpreted."""

    interaction: Interaction
    r"""Required. The interaction request template to be executed."""

    display_name: Optional[str] = None
    r"""Optional. The display name of the trigger."""

    environment_id: Optional[str] = None
    r"""Optional. The environment ID for the trigger execution."""

    max_consecutive_failures: Optional[int] = None
    r"""Optional. The maximum number of consecutive failures allowed before the trigger is automatically paused (status becomes ERROR)."""

    execution_timeout_seconds: Optional[int] = None
    r"""Optional. The execution timeout for the triggered interaction."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "display_name",
                "environment_id",
                "max_consecutive_failures",
                "execution_timeout_seconds",
            ]
        )
        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
