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

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";
import {
  ImageURL,
  ImageURL$inboundSchema,
  ImageURL$Outbound,
  ImageURL$outboundSchema,
} from "./imageurl.js";

export type ImageUrlUnion = ImageURL | string;

/**
 * {"type":"image_url","image_url":{"url":"data:image/png;base64,iVBORw0
 */
export type ImageURLChunk = {
  type: "image_url";
  imageUrl: ImageURL | string;
};

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

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

export function imageUrlUnionToJSON(imageUrlUnion: ImageUrlUnion): string {
  return JSON.stringify(ImageUrlUnion$outboundSchema.parse(imageUrlUnion));
}
export function imageUrlUnionFromJSON(
  jsonString: string,
): SafeParseResult<ImageUrlUnion, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ImageUrlUnion$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ImageUrlUnion' from JSON`,
  );
}

/** @internal */
export const ImageURLChunk$inboundSchema: z.ZodType<ImageURLChunk, unknown> = z
  .object({
    type: z.literal("image_url"),
    image_url: smartUnion([ImageURL$inboundSchema, z.string()]),
  }).transform((v) => {
    return remap$(v, {
      "image_url": "imageUrl",
    });
  });
/** @internal */
export type ImageURLChunk$Outbound = {
  type: "image_url";
  image_url: ImageURL$Outbound | string;
};

/** @internal */
export const ImageURLChunk$outboundSchema: z.ZodType<
  ImageURLChunk$Outbound,
  ImageURLChunk
> = z.object({
  type: z.literal("image_url"),
  imageUrl: smartUnion([ImageURL$outboundSchema, z.string()]),
}).transform((v) => {
  return remap$(v, {
    imageUrl: "image_url",
  });
});

export function imageURLChunkToJSON(imageURLChunk: ImageURLChunk): string {
  return JSON.stringify(ImageURLChunk$outboundSchema.parse(imageURLChunk));
}
export function imageURLChunkFromJSON(
  jsonString: string,
): SafeParseResult<ImageURLChunk, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ImageURLChunk$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ImageURLChunk' from JSON`,
  );
}
