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

import * as z from "zod/v4";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { smartUnion } from "../../types/smartUnion.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import { ContentChunk, ContentChunk$inboundSchema } from "./contentchunk.js";
import { ToolCall, ToolCall$inboundSchema } from "./toolcall.js";

export type DeltaMessageContent = string | Array<ContentChunk>;

export type DeltaMessage = {
  role?: string | null | undefined;
  content?: string | Array<ContentChunk> | null | undefined;
  toolCalls?: Array<ToolCall> | null | undefined;
};

/** @internal */
export const DeltaMessageContent$inboundSchema: z.ZodType<
  DeltaMessageContent,
  unknown
> = smartUnion([z.string(), z.array(ContentChunk$inboundSchema)]);

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

/** @internal */
export const DeltaMessage$inboundSchema: z.ZodType<DeltaMessage, unknown> = z
  .object({
    role: z.nullable(z.string()).optional(),
    content: z.nullable(
      smartUnion([z.string(), z.array(ContentChunk$inboundSchema)]),
    ).optional(),
    tool_calls: z.nullable(z.array(ToolCall$inboundSchema)).optional(),
  }).transform((v) => {
    return remap$(v, {
      "tool_calls": "toolCalls",
    });
  });

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