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

import * as z from "zod/v4";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  CompletionResponseStreamChoice,
  CompletionResponseStreamChoice$inboundSchema,
} from "./completionresponsestreamchoice.js";
import { UsageInfo, UsageInfo$inboundSchema } from "./usageinfo.js";

export type CompletionChunk = {
  id: string;
  object?: string | undefined;
  created?: number | undefined;
  model: string;
  usage?: UsageInfo | undefined;
  choices: Array<CompletionResponseStreamChoice>;
};

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

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