/*
 * 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 DocumentURLChunk = {
  type?: "document_url" | undefined;
  documentUrl: string;
  /**
   * The filename of the document
   */
  documentName?: string | null | undefined;
};

/** @internal */
export const DocumentURLChunk$inboundSchema: z.ZodType<
  DocumentURLChunk,
  z.ZodTypeDef,
  unknown
> = z.object({
  type: z.literal("document_url").default("document_url"),
  document_url: z.string(),
  document_name: z.nullable(z.string()).optional(),
}).transform((v) => {
  return remap$(v, {
    "document_url": "documentUrl",
    "document_name": "documentName",
  });
});
/** @internal */
export type DocumentURLChunk$Outbound = {
  type: "document_url";
  document_url: string;
  document_name?: string | null | undefined;
};

/** @internal */
export const DocumentURLChunk$outboundSchema: z.ZodType<
  DocumentURLChunk$Outbound,
  z.ZodTypeDef,
  DocumentURLChunk
> = z.object({
  type: z.literal("document_url").default("document_url" as const),
  documentUrl: z.string(),
  documentName: z.nullable(z.string()).optional(),
}).transform((v) => {
  return remap$(v, {
    documentUrl: "document_url",
    documentName: "document_name",
  });
});

export function documentURLChunkToJSON(
  documentURLChunk: DocumentURLChunk,
): string {
  return JSON.stringify(
    DocumentURLChunk$outboundSchema.parse(documentURLChunk),
  );
}
export function documentURLChunkFromJSON(
  jsonString: string,
): SafeParseResult<DocumentURLChunk, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => DocumentURLChunk$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'DocumentURLChunk' from JSON`,
  );
}
