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

from __future__ import annotations
from .schedulecalendar import ScheduleCalendar, ScheduleCalendarTypedDict
from .scheduleinterval import ScheduleInterval, ScheduleIntervalTypedDict
from .schedulepolicy import SchedulePolicy, SchedulePolicyTypedDict
from datetime import datetime
from mistralai.client.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from pydantic import model_serializer
from typing import Any, List, Optional
from typing_extensions import NotRequired, TypedDict


class ScheduleDefinitionTypedDict(TypedDict):
    r"""Specification of the times scheduled actions may occur.

    The times are the union of :py:attr:`calendars`, :py:attr:`intervals`, and
    :py:attr:`cron_expressions` excluding anything in :py:attr:`skip`.

    Used for input where schedule_id is optional (can be provided or auto-generated).
    """

    input: Any
    r"""Input to provide to the workflow when starting it."""
    calendars: NotRequired[List[ScheduleCalendarTypedDict]]
    r"""Calendar-based specification of times."""
    intervals: NotRequired[List[ScheduleIntervalTypedDict]]
    r"""Interval-based specification of times."""
    cron_expressions: NotRequired[List[str]]
    r"""Cron-based specification of times."""
    skip: NotRequired[List[ScheduleCalendarTypedDict]]
    r"""Set of calendar times to skip."""
    start_at: NotRequired[Nullable[datetime]]
    r"""Time after which the first action may be run."""
    end_at: NotRequired[Nullable[datetime]]
    r"""Time after which no more actions will be run."""
    jitter: NotRequired[Nullable[str]]
    r"""Jitter to apply each action.

    An action's scheduled time will be incremented by a random value between 0
    and this value if present (but not past the next schedule).

    """
    time_zone_name: NotRequired[Nullable[str]]
    r"""IANA time zone name, for example ``US/Central``."""
    policy: NotRequired[SchedulePolicyTypedDict]
    schedule_id: NotRequired[Nullable[str]]
    r"""Unique identifier for the schedule."""


class ScheduleDefinition(BaseModel):
    r"""Specification of the times scheduled actions may occur.

    The times are the union of :py:attr:`calendars`, :py:attr:`intervals`, and
    :py:attr:`cron_expressions` excluding anything in :py:attr:`skip`.

    Used for input where schedule_id is optional (can be provided or auto-generated).
    """

    input: Any
    r"""Input to provide to the workflow when starting it."""

    calendars: Optional[List[ScheduleCalendar]] = None
    r"""Calendar-based specification of times."""

    intervals: Optional[List[ScheduleInterval]] = None
    r"""Interval-based specification of times."""

    cron_expressions: Optional[List[str]] = None
    r"""Cron-based specification of times."""

    skip: Optional[List[ScheduleCalendar]] = None
    r"""Set of calendar times to skip."""

    start_at: OptionalNullable[datetime] = UNSET
    r"""Time after which the first action may be run."""

    end_at: OptionalNullable[datetime] = UNSET
    r"""Time after which no more actions will be run."""

    jitter: OptionalNullable[str] = UNSET
    r"""Jitter to apply each action.

    An action's scheduled time will be incremented by a random value between 0
    and this value if present (but not past the next schedule).

    """

    time_zone_name: OptionalNullable[str] = UNSET
    r"""IANA time zone name, for example ``US/Central``."""

    policy: Optional[SchedulePolicy] = None

    schedule_id: OptionalNullable[str] = UNSET
    r"""Unique identifier for the schedule."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "calendars",
                "intervals",
                "cron_expressions",
                "skip",
                "start_at",
                "end_at",
                "jitter",
                "time_zone_name",
                "policy",
                "schedule_id",
            ]
        )
        nullable_fields = set(
            ["start_at", "end_at", "jitter", "time_zone_name", "schedule_id"]
        )
        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))
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

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

        return m
