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

export type ImageURLChunkImageURL = ImageURL | string;

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

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

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

export function imageURLChunkImageURLToJSON(
  imageURLChunkImageURL: ImageURLChunkImageURL,
): string {
  return JSON.stringify(
    ImageURLChunkImageURL$outboundSchema.parse(imageURLChunkImageURL),
  );
}
export function imageURLChunkImageURLFromJSON(
  jsonString: string,
): SafeParseResult<ImageURLChunkImageURL, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ImageURLChunkImageURL$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ImageURLChunkImageURL' from JSON`,
  );
}

/** @internal */
export const ImageURLChunk$inboundSchema: z.ZodType<
  ImageURLChunk,
  z.ZodTypeDef,
  unknown
> = z.object({
  type: z.literal("image_url").default("image_url"),
  image_url: z.union([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,
  z.ZodTypeDef,
  ImageURLChunk
> = z.object({
  type: z.literal("image_url").default("image_url" as const),
  imageUrl: z.union([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`,
  );
}
