"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
# @generated-id: f326afe63958

from __future__ import annotations
from .scheduleoverlappolicy import ScheduleOverlapPolicy
from mistralai.client.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Optional
from typing_extensions import NotRequired, TypedDict


class SchedulePolicyTypedDict(TypedDict):
    catchup_window_seconds: NotRequired[int]
    r"""After a Temporal server is unavailable, amount of time in seconds in the past to execute missed actions."""
    overlap: NotRequired[ScheduleOverlapPolicy]
    r"""Controls what happens when a workflow would be started by a schedule but
    one is already running.
    """
    pause_on_failure: NotRequired[bool]
    r"""Whether to pause the schedule after a workflow failure."""


class SchedulePolicy(BaseModel):
    catchup_window_seconds: Optional[int] = 31536000
    r"""After a Temporal server is unavailable, amount of time in seconds in the past to execute missed actions."""

    overlap: Optional[ScheduleOverlapPolicy] = None
    r"""Controls what happens when a workflow would be started by a schedule but
    one is already running.
    """

    pause_on_failure: Optional[bool] = False
    r"""Whether to pause the schedule after a workflow failure."""

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