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

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

export type ToolMessageContent = string | Array<ContentChunk>;

export type ToolMessage = {
  role?: "tool" | undefined;
  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,
  z.ZodTypeDef,
  ToolMessageContent
> = z.union([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,
  z.ZodTypeDef,
  ToolMessage
> = z.object({
  role: z.literal("tool").default("tool" as const),
  content: z.nullable(
    z.union([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));
}
