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

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,
  ContentChunk$Outbound,
  ContentChunk$outboundSchema,
} from "./contentchunk.js";
import {
  ToolCall,
  ToolCall$inboundSchema,
  ToolCall$Outbound,
  ToolCall$outboundSchema,
} from "./toolcall.js";

export type AssistantMessageContent = string | Array<ContentChunk>;

export type AssistantMessage = {
  role?: "assistant" | undefined;
  content?: string | Array<ContentChunk> | null | undefined;
  toolCalls?: Array<ToolCall> | null | undefined;
  /**
   * Set this to `true` when adding an assistant message as prefix to condition the model response. The role of the prefix message is to force the model to start its answer by the content of the message.
   */
  prefix?: boolean | undefined;
};

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

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

export function assistantMessageContentToJSON(
  assistantMessageContent: AssistantMessageContent,
): string {
  return JSON.stringify(
    AssistantMessageContent$outboundSchema.parse(assistantMessageContent),
  );
}
export function assistantMessageContentFromJSON(
  jsonString: string,
): SafeParseResult<AssistantMessageContent, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => AssistantMessageContent$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'AssistantMessageContent' from JSON`,
  );
}

/** @internal */
export const AssistantMessage$inboundSchema: z.ZodType<
  AssistantMessage,
  unknown
> = z.object({
  role: z.literal("assistant").default("assistant"),
  content: z.nullable(
    smartUnion([z.string(), z.array(ContentChunk$inboundSchema)]),
  ).optional(),
  tool_calls: z.nullable(z.array(ToolCall$inboundSchema)).optional(),
  prefix: z.boolean().default(false),
}).transform((v) => {
  return remap$(v, {
    "tool_calls": "toolCalls",
  });
});
/** @internal */
export type AssistantMessage$Outbound = {
  role: "assistant";
  content?: string | Array<ContentChunk$Outbound> | null | undefined;
  tool_calls?: Array<ToolCall$Outbound> | null | undefined;
  prefix: boolean;
};

/** @internal */
export const AssistantMessage$outboundSchema: z.ZodType<
  AssistantMessage$Outbound,
  AssistantMessage
> = z.object({
  role: z.literal("assistant").default("assistant" as const),
  content: z.nullable(
    smartUnion([z.string(), z.array(ContentChunk$outboundSchema)]),
  ).optional(),
  toolCalls: z.nullable(z.array(ToolCall$outboundSchema)).optional(),
  prefix: z.boolean().default(false),
}).transform((v) => {
  return remap$(v, {
    toolCalls: "tool_calls",
  });
});

export function assistantMessageToJSON(
  assistantMessage: AssistantMessage,
): string {
  return JSON.stringify(
    AssistantMessage$outboundSchema.parse(assistantMessage),
  );
}
export function assistantMessageFromJSON(
  jsonString: string,
): SafeParseResult<AssistantMessage, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => AssistantMessage$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'AssistantMessage' from JSON`,
  );
}
