/*
 * 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 { ClosedEnum } from "../../types/enums.js";
import {
  ContentChunk,
  ContentChunk$Outbound,
  ContentChunk$outboundSchema,
} from "./contentchunk.js";

export type ToolMessageContent = string | Array<ContentChunk>;

export const ToolMessageRole = {
  Tool: "tool",
} as const;
export type ToolMessageRole = ClosedEnum<typeof ToolMessageRole>;

export type ToolMessage = {
  content: string | Array<ContentChunk> | null;
  toolCallId?: string | null | undefined;
  name?: string | null | undefined;
  role?: ToolMessageRole | 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 const ToolMessageRole$outboundSchema: z.ZodNativeEnum<
  typeof ToolMessageRole
> = z.nativeEnum(ToolMessageRole);

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

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

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