/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 * @generated-id: d73113114e08
 */

import * as z from "zod/v4";
import { remap as remap$ } from "../../lib/primitives.js";
import {
  ScheduleCalendar,
  ScheduleCalendar$Outbound,
  ScheduleCalendar$outboundSchema,
} from "./schedulecalendar.js";
import {
  ScheduleInterval,
  ScheduleInterval$Outbound,
  ScheduleInterval$outboundSchema,
} from "./scheduleinterval.js";
import {
  SchedulePolicy,
  SchedulePolicy$Outbound,
  SchedulePolicy$outboundSchema,
} from "./schedulepolicy.js";

/**
 * Specification of the times scheduled actions may occur.
 *
 * @remarks
 *
 * 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).
 */
export type ScheduleDefinition = {
  /**
   * Input to provide to the workflow when starting it.
   */
  input: any;
  /**
   * Calendar-based specification of times.
   */
  calendars?: Array<ScheduleCalendar> | undefined;
  /**
   * Interval-based specification of times.
   */
  intervals?: Array<ScheduleInterval> | undefined;
  /**
   * Cron-based specification of times.
   */
  cronExpressions?: Array<string> | undefined;
  /**
   * Set of calendar times to skip.
   */
  skip?: Array<ScheduleCalendar> | undefined;
  /**
   * Time after which the first action may be run.
   */
  startAt?: Date | null | undefined;
  /**
   * Time after which no more actions will be run.
   */
  endAt?: Date | null | undefined;
  /**
   * Jitter to apply each action.
   *
   * @remarks
   *
   * 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).
   */
  jitter?: string | null | undefined;
  /**
   * IANA time zone name, for example ``US/Central``.
   */
  timeZoneName?: string | null | undefined;
  policy?: SchedulePolicy | undefined;
  /**
   * Maximum number of times this schedule will trigger a workflow execution. Once this limit is reached, no further executions are triggered automatically. null means unlimited.
   */
  maxExecutions?: number | null | undefined;
  /**
   * Unique identifier for the schedule.
   */
  scheduleId?: string | null | undefined;
};

/** @internal */
export type ScheduleDefinition$Outbound = {
  input: any;
  calendars?: Array<ScheduleCalendar$Outbound> | undefined;
  intervals?: Array<ScheduleInterval$Outbound> | undefined;
  cron_expressions?: Array<string> | undefined;
  skip?: Array<ScheduleCalendar$Outbound> | undefined;
  start_at?: string | null | undefined;
  end_at?: string | null | undefined;
  jitter?: string | null | undefined;
  time_zone_name?: string | null | undefined;
  policy?: SchedulePolicy$Outbound | undefined;
  max_executions?: number | null | undefined;
  schedule_id?: string | null | undefined;
};

/** @internal */
export const ScheduleDefinition$outboundSchema: z.ZodType<
  ScheduleDefinition$Outbound,
  ScheduleDefinition
> = z.object({
  input: z.any(),
  calendars: z.array(ScheduleCalendar$outboundSchema).optional(),
  intervals: z.array(ScheduleInterval$outboundSchema).optional(),
  cronExpressions: z.array(z.string()).optional(),
  skip: z.array(ScheduleCalendar$outboundSchema).optional(),
  startAt: z.nullable(z.date().transform(v => v.toISOString())).optional(),
  endAt: z.nullable(z.date().transform(v => v.toISOString())).optional(),
  jitter: z.nullable(z.string()).optional(),
  timeZoneName: z.nullable(z.string()).optional(),
  policy: SchedulePolicy$outboundSchema.optional(),
  maxExecutions: z.nullable(z.int()).optional(),
  scheduleId: z.nullable(z.string()).optional(),
}).transform((v) => {
  return remap$(v, {
    cronExpressions: "cron_expressions",
    startAt: "start_at",
    endAt: "end_at",
    timeZoneName: "time_zone_name",
    maxExecutions: "max_executions",
    scheduleId: "schedule_id",
  });
});

export function scheduleDefinitionToJSON(
  scheduleDefinition: ScheduleDefinition,
): string {
  return JSON.stringify(
    ScheduleDefinition$outboundSchema.parse(scheduleDefinition),
  );
}
