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

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 ScheduleDefinitionOutputTypedDict(TypedDict):
    r"""Output representation of a schedule with required schedule_id.

    Used when returning schedules from the API where schedule_id is always present.
    """

    input: Any
    r"""Input to provide to the workflow when starting it."""
    schedule_id: str
    r"""Unique identifier for the schedule."""
    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]


class ScheduleDefinitionOutput(BaseModel):
    r"""Output representation of a schedule with required schedule_id.

    Used when returning schedules from the API where schedule_id is always present.
    """

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

    schedule_id: str
    r"""Unique identifier for the schedule."""

    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

    @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",
            ]
        )
        nullable_fields = set(["start_at", "end_at", "jitter", "time_zone_name"])
        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
