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

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";

/**
 * A payload containing arbitrary JSON data.
 *
 * @remarks
 *
 * Used for complete state snapshots or final results.
 * When encrypted, the value field contains base64-encoded encrypted data
 * and encoding_options indicates the type of encryption applied.
 */
export type JSONPayloadResponse = {
  /**
   * Discriminator indicating this is a raw JSON payload.
   */
  type: "json";
  /**
   * The JSON-serializable payload value. When encrypted, contains base64-encoded data.
   */
  value: any;
  /**
   * Encoding options applied to the payload.
   */
  encodingOptions?: Array<EncodedPayloadOptions> | null | undefined;
};

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

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