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

import * as z from "zod/v3";
import { safeParse } from "../lib/schemas.js";
import { ClosedEnum } from "../types/enums.js";
import { Result as SafeParseResult } from "../types/fp.js";
import * as types from "../types/primitives.js";
import {
  ConnectServiceSyncError,
  ConnectServiceSyncError$inboundSchema,
} from "./connectservicesyncerror.js";
import { SDKValidationError } from "./sdkvalidationerror.js";

/**
 * done means the external service was updated. required means the Vercel update was saved, but provider-side configuration still needs attention.
 */
export const ConnectServiceSyncStatus = {
  Done: "done",
  Required: "required",
} as const;
/**
 * done means the external service was updated. required means the Vercel update was saved, but provider-side configuration still needs attention.
 */
export type ConnectServiceSyncStatus = ClosedEnum<
  typeof ConnectServiceSyncStatus
>;

/**
 * Provider-side configuration synchronization result.
 */
export type ConnectServiceSync = {
  /**
   * done means the external service was updated. required means the Vercel update was saved, but provider-side configuration still needs attention.
   */
  status: ConnectServiceSyncStatus;
  /**
   * Provider synchronization errors. Present when serviceSync.status is required.
   */
  errors?: Array<ConnectServiceSyncError> | undefined;
};

/** @internal */
export const ConnectServiceSyncStatus$inboundSchema: z.ZodNativeEnum<
  typeof ConnectServiceSyncStatus
> = z.nativeEnum(ConnectServiceSyncStatus);

/** @internal */
export const ConnectServiceSync$inboundSchema: z.ZodType<
  ConnectServiceSync,
  z.ZodTypeDef,
  unknown
> = z.object({
  status: ConnectServiceSyncStatus$inboundSchema,
  errors: types.optional(z.array(ConnectServiceSyncError$inboundSchema)),
});

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