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

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 {
  AgentHandoffEntry,
  AgentHandoffEntry$inboundSchema,
} from "./agenthandoffentry.js";
import {
  ConversationUsageInfo,
  ConversationUsageInfo$inboundSchema,
} from "./conversationusageinfo.js";
import {
  FunctionCallEntry,
  FunctionCallEntry$inboundSchema,
} from "./functioncallentry.js";
import {
  MessageOutputEntry,
  MessageOutputEntry$inboundSchema,
} from "./messageoutputentry.js";
import {
  ToolExecutionEntry,
  ToolExecutionEntry$inboundSchema,
} from "./toolexecutionentry.js";

export type ConversationResponseOutput =
  | AgentHandoffEntry
  | FunctionCallEntry
  | ToolExecutionEntry
  | MessageOutputEntry;

/**
 * The response after appending new entries to the conversation.
 */
export type ConversationResponse = {
  object: "conversation.response";
  conversationId: string;
  outputs: Array<
    | AgentHandoffEntry
    | FunctionCallEntry
    | ToolExecutionEntry
    | MessageOutputEntry
  >;
  usage: ConversationUsageInfo;
  guardrails?: Array<{ [k: string]: any }> | null | undefined;
};

/** @internal */
export const ConversationResponseOutput$inboundSchema: z.ZodType<
  ConversationResponseOutput,
  unknown
> = smartUnion([
  AgentHandoffEntry$inboundSchema,
  FunctionCallEntry$inboundSchema,
  ToolExecutionEntry$inboundSchema,
  MessageOutputEntry$inboundSchema,
]);

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

/** @internal */
export const ConversationResponse$inboundSchema: z.ZodType<
  ConversationResponse,
  unknown
> = z.object({
  object: z.literal("conversation.response").default("conversation.response"),
  conversation_id: z.string(),
  outputs: z.array(
    smartUnion([
      AgentHandoffEntry$inboundSchema,
      FunctionCallEntry$inboundSchema,
      ToolExecutionEntry$inboundSchema,
      MessageOutputEntry$inboundSchema,
    ]),
  ),
  usage: ConversationUsageInfo$inboundSchema,
  guardrails: z.nullable(z.array(z.record(z.string(), z.any()))).optional(),
}).transform((v) => {
  return remap$(v, {
    "conversation_id": "conversationId",
  });
});

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