/*
 * 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 {
  EmbeddingResponseData,
  EmbeddingResponseData$inboundSchema,
} from "./embeddingresponsedata.js";
import { UsageInfo, UsageInfo$inboundSchema } from "./usageinfo.js";

export type EmbeddingResponse = {
  id: string;
  object: string;
  model: string;
  usage: UsageInfo;
  data: Array<EmbeddingResponseData>;
};

/** @internal */
export const EmbeddingResponse$inboundSchema: z.ZodType<
  EmbeddingResponse,
  z.ZodTypeDef,
  unknown
> = z.object({
  id: z.string(),
  object: z.string(),
  model: z.string(),
  usage: UsageInfo$inboundSchema,
  data: z.array(EmbeddingResponseData$inboundSchema),
});

export function embeddingResponseFromJSON(
  jsonString: string,
): SafeParseResult<EmbeddingResponse, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => EmbeddingResponse$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'EmbeddingResponse' from JSON`,
  );
}
