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

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 { smartUnion } from "../../types/smartUnion.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

export type ReferenceId = number | string;

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

/** @internal */
export const ReferenceId$inboundSchema: z.ZodType<ReferenceId, unknown> =
  smartUnion([z.int(), z.string()]);
/** @internal */
export type ReferenceId$Outbound = number | string;

/** @internal */
export const ReferenceId$outboundSchema: z.ZodType<
  ReferenceId$Outbound,
  ReferenceId
> = smartUnion([z.int(), z.string()]);

export function referenceIdToJSON(referenceId: ReferenceId): string {
  return JSON.stringify(ReferenceId$outboundSchema.parse(referenceId));
}
export function referenceIdFromJSON(
  jsonString: string,
): SafeParseResult<ReferenceId, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ReferenceId$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ReferenceId' from JSON`,
  );
}

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

/** @internal */
export const ReferenceChunk$outboundSchema: z.ZodType<
  ReferenceChunk$Outbound,
  ReferenceChunk
> = z.object({
  type: z.literal("reference").default("reference" as const),
  referenceIds: z.array(smartUnion([z.int(), z.string()])),
}).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`,
  );
}
