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

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 {
  EncodedPayloadOptions,
  EncodedPayloadOptions$inboundSchema,
} from "./encodedpayloadoptions.js";
import {
  JSONPatchPayloadValueResponse,
  JSONPatchPayloadValueResponse$inboundSchema,
} from "./jsonpatchpayloadvalueresponse.js";

/**
 * A payload containing a list of JSON Patch operations.
 *
 * @remarks
 *
 * Used for streaming incremental updates to workflow state.
 * When encrypted, the value field contains base64-encoded encrypted data
 * and encoding_options indicates the type of encryption applied.
 */
export type JSONPatchPayloadResponse = {
  /**
   * Discriminator indicating this is a JSON Patch payload.
   */
  type: "json_patch";
  value: JSONPatchPayloadValueResponse;
  /**
   * Encoding options applied to the payload.
   */
  encodingOptions?: Array<EncodedPayloadOptions> | null | undefined;
};

/** @internal */
export const JSONPatchPayloadResponse$inboundSchema: z.ZodType<
  JSONPatchPayloadResponse,
  unknown
> = z.object({
  type: z.literal("json_patch"),
  value: JSONPatchPayloadValueResponse$inboundSchema,
  encoding_options: z.nullable(z.array(EncodedPayloadOptions$inboundSchema))
    .optional(),
}).transform((v) => {
  return remap$(v, {
    "encoding_options": "encodingOptions",
  });
});

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