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

import * as z from "zod/v4";
import { remap as remap$ } from "../../lib/primitives.js";
import { smartUnion } from "../../types/smartUnion.js";
import {
  ContentChunk,
  ContentChunk$Outbound,
  ContentChunk$outboundSchema,
} from "./contentchunk.js";

export type ToolMessageContent = string | Array<ContentChunk>;

export type ToolMessage = {
  role: "tool";
  content: string | Array<ContentChunk> | null;
  toolCallId?: string | null | undefined;
  name?: string | null | undefined;
};

/** @internal */
export type ToolMessageContent$Outbound = string | Array<ContentChunk$Outbound>;

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

export function toolMessageContentToJSON(
  toolMessageContent: ToolMessageContent,
): string {
  return JSON.stringify(
    ToolMessageContent$outboundSchema.parse(toolMessageContent),
  );
}

/** @internal */
export type ToolMessage$Outbound = {
  role: "tool";
  content: string | Array<ContentChunk$Outbound> | null;
  tool_call_id?: string | null | undefined;
  name?: string | null | undefined;
};

/** @internal */
export const ToolMessage$outboundSchema: z.ZodType<
  ToolMessage$Outbound,
  ToolMessage
> = z.object({
  role: z.literal("tool"),
  content: z.nullable(
    smartUnion([z.string(), z.array(ContentChunk$outboundSchema)]),
  ),
  toolCallId: z.nullable(z.string()).optional(),
  name: z.nullable(z.string()).optional(),
}).transform((v) => {
  return remap$(v, {
    toolCallId: "tool_call_id",
  });
});

export function toolMessageToJSON(toolMessage: ToolMessage): string {
  return JSON.stringify(ToolMessage$outboundSchema.parse(toolMessage));
}
