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

import * as z from "zod/v3";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  ImageDetail,
  ImageDetail$inboundSchema,
  ImageDetail$outboundSchema,
} from "./imagedetail.js";

export type ImageURL = {
  url: string;
  detail?: ImageDetail | null | undefined;
};

/** @internal */
export const ImageURL$inboundSchema: z.ZodType<
  ImageURL,
  z.ZodTypeDef,
  unknown
> = z.object({
  url: z.string(),
  detail: z.nullable(ImageDetail$inboundSchema).optional(),
});
/** @internal */
export type ImageURL$Outbound = {
  url: string;
  detail?: string | null | undefined;
};

/** @internal */
export const ImageURL$outboundSchema: z.ZodType<
  ImageURL$Outbound,
  z.ZodTypeDef,
  ImageURL
> = z.object({
  url: z.string(),
  detail: z.nullable(ImageDetail$outboundSchema).optional(),
});

export function imageURLToJSON(imageURL: ImageURL): string {
  return JSON.stringify(ImageURL$outboundSchema.parse(imageURL));
}
export function imageURLFromJSON(
  jsonString: string,
): SafeParseResult<ImageURL, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ImageURL$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ImageURL' from JSON`,
  );
}
