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

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 {
  ScheduleOverlapPolicy,
  ScheduleOverlapPolicy$inboundSchema,
  ScheduleOverlapPolicy$outboundSchema,
} from "./scheduleoverlappolicy.js";

export type SchedulePolicy = {
  /**
   * After a Temporal server is unavailable, amount of time in seconds in the past to execute missed actions.
   */
  catchupWindowSeconds?: number | undefined;
  /**
   * Controls what happens when a workflow would be started by a schedule but
   *
   * @remarks
   * one is already running.
   */
  overlap?: ScheduleOverlapPolicy | undefined;
  /**
   * Whether to pause the schedule after a workflow failure.
   */
  pauseOnFailure?: boolean | undefined;
};

/** @internal */
export const SchedulePolicy$inboundSchema: z.ZodType<SchedulePolicy, unknown> =
  z.object({
    catchup_window_seconds: z.int().default(31536000),
    overlap: ScheduleOverlapPolicy$inboundSchema.optional(),
    pause_on_failure: z.boolean().default(false),
  }).transform((v) => {
    return remap$(v, {
      "catchup_window_seconds": "catchupWindowSeconds",
      "pause_on_failure": "pauseOnFailure",
    });
  });
/** @internal */
export type SchedulePolicy$Outbound = {
  catchup_window_seconds: number;
  overlap?: number | undefined;
  pause_on_failure: boolean;
};

/** @internal */
export const SchedulePolicy$outboundSchema: z.ZodType<
  SchedulePolicy$Outbound,
  SchedulePolicy
> = z.object({
  catchupWindowSeconds: z.int().default(31536000),
  overlap: ScheduleOverlapPolicy$outboundSchema.optional(),
  pauseOnFailure: z.boolean().default(false),
}).transform((v) => {
  return remap$(v, {
    catchupWindowSeconds: "catchup_window_seconds",
    pauseOnFailure: "pause_on_failure",
  });
});

export function schedulePolicyToJSON(schedulePolicy: SchedulePolicy): string {
  return JSON.stringify(SchedulePolicy$outboundSchema.parse(schedulePolicy));
}
export function schedulePolicyFromJSON(
  jsonString: string,
): SafeParseResult<SchedulePolicy, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => SchedulePolicy$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'SchedulePolicy' from JSON`,
  );
}
