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

export type ChatCompletionResponse = {
  id: string;
  object: string;
  model: string;
  usage: UsageInfo;
  created: number;
  choices: Array<ChatCompletionChoice>;
};

/** @internal */
export const ChatCompletionResponse$inboundSchema: z.ZodType<
  ChatCompletionResponse,
  z.ZodTypeDef,
  unknown
> = z.object({
  id: z.string(),
  object: z.string(),
  model: z.string(),
  usage: UsageInfo$inboundSchema,
  created: z.number().int(),
  choices: z.array(ChatCompletionChoice$inboundSchema),
});

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