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

import * as z from "zod/v3";
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";

export type ReferenceChunk = {
  type?: "reference" | undefined;
  referenceIds: Array<number>;
};

/** @internal */
export const ReferenceChunk$inboundSchema: z.ZodType<
  ReferenceChunk,
  z.ZodTypeDef,
  unknown
> = z.object({
  type: z.literal("reference").default("reference"),
  reference_ids: z.array(z.number().int()),
}).transform((v) => {
  return remap$(v, {
    "reference_ids": "referenceIds",
  });
});
/** @internal */
export type ReferenceChunk$Outbound = {
  type: "reference";
  reference_ids: Array<number>;
};

/** @internal */
export const ReferenceChunk$outboundSchema: z.ZodType<
  ReferenceChunk$Outbound,
  z.ZodTypeDef,
  ReferenceChunk
> = z.object({
  type: z.literal("reference").default("reference" as const),
  referenceIds: z.array(z.number().int()),
}).transform((v) => {
  return remap$(v, {
    referenceIds: "reference_ids",
  });
});

export function referenceChunkToJSON(referenceChunk: ReferenceChunk): string {
  return JSON.stringify(ReferenceChunk$outboundSchema.parse(referenceChunk));
}
export function referenceChunkFromJSON(
  jsonString: string,
): SafeParseResult<ReferenceChunk, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ReferenceChunk$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ReferenceChunk' from JSON`,
  );
}
