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

import * as z from "zod/v4";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  ScheduleCalendar,
  ScheduleCalendar$inboundSchema,
} from "./schedulecalendar.js";
import {
  ScheduleFutureExecution,
  ScheduleFutureExecution$inboundSchema,
} from "./schedulefutureexecution.js";
import {
  ScheduleInterval,
  ScheduleInterval$inboundSchema,
} from "./scheduleinterval.js";
import {
  SchedulePolicy,
  SchedulePolicy$inboundSchema,
} from "./schedulepolicy.js";
import {
  ScheduleRecentExecution,
  ScheduleRecentExecution$inboundSchema,
} from "./schedulerecentexecution.js";

/**
 * Output representation of a schedule with required schedule_id.
 *
 * @remarks
 *
 * Used when returning schedules from the API where schedule_id is always present.
 */
export type ScheduleDefinitionOutput = {
  /**
   * 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;
  /**
   * Unique identifier for the schedule.
   */
  scheduleId: string;
  /**
   * Remaining workflow executions before this schedule stops triggering automatically. null means unlimited; 0 means the limit has been reached and the schedule is exhausted.
   */
  remainingExecutions?: number | null | undefined;
  /**
   * Name of the workflow this schedule triggers.
   */
  workflowName: string;
  /**
   * Whether the schedule is currently paused.
   */
  paused: boolean;
  /**
   * Human-readable note associated with the current pause or resume state.
   */
  note?: string | null | undefined;
  /**
   * Upcoming scheduled executions (10 next executions, earliest first).
   */
  futureExecutions?: Array<ScheduleFutureExecution> | undefined;
  /**
   * Most recent scheduled executions (10 most recent, newest last).
   */
  recentExecutions?: Array<ScheduleRecentExecution> | undefined;
};

/** @internal */
export const ScheduleDefinitionOutput$inboundSchema: z.ZodType<
  ScheduleDefinitionOutput,
  unknown
> = z.object({
  input: z.any(),
  calendars: z.array(ScheduleCalendar$inboundSchema).optional(),
  intervals: z.array(ScheduleInterval$inboundSchema).optional(),
  cron_expressions: z.array(z.string()).optional(),
  skip: z.array(ScheduleCalendar$inboundSchema).optional(),
  start_at: z.nullable(
    z.iso.datetime({ offset: true }).transform(v => new Date(v)),
  ).optional(),
  end_at: z.nullable(
    z.iso.datetime({ offset: true }).transform(v => new Date(v)),
  ).optional(),
  jitter: z.nullable(z.string()).optional(),
  time_zone_name: z.nullable(z.string()).optional(),
  policy: SchedulePolicy$inboundSchema.optional(),
  schedule_id: z.string(),
  remaining_executions: z.nullable(z.int()).optional(),
  workflow_name: z.string(),
  paused: z.boolean(),
  note: z.nullable(z.string()).optional(),
  future_executions: z.array(ScheduleFutureExecution$inboundSchema).optional(),
  recent_executions: z.array(ScheduleRecentExecution$inboundSchema).optional(),
}).transform((v) => {
  return remap$(v, {
    "cron_expressions": "cronExpressions",
    "start_at": "startAt",
    "end_at": "endAt",
    "time_zone_name": "timeZoneName",
    "schedule_id": "scheduleId",
    "remaining_executions": "remainingExecutions",
    "workflow_name": "workflowName",
    "future_executions": "futureExecutions",
    "recent_executions": "recentExecutions",
  });
});

export function scheduleDefinitionOutputFromJSON(
  jsonString: string,
): SafeParseResult<ScheduleDefinitionOutput, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ScheduleDefinitionOutput$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ScheduleDefinitionOutput' from JSON`,
  );
}
