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

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 {
  FunctionCallEntry,
  FunctionCallEntry$inboundSchema,
} from "./functioncallentry.js";
import {
  FunctionResultEntry,
  FunctionResultEntry$inboundSchema,
} from "./functionresultentry.js";
import {
  MessageInputEntry,
  MessageInputEntry$inboundSchema,
} from "./messageinputentry.js";
import {
  MessageOutputEntry,
  MessageOutputEntry$inboundSchema,
} from "./messageoutputentry.js";
import {
  ToolExecutionEntry,
  ToolExecutionEntry$inboundSchema,
} from "./toolexecutionentry.js";

export type Entry =
  | AgentHandoffEntry
  | FunctionCallEntry
  | MessageInputEntry
  | FunctionResultEntry
  | ToolExecutionEntry
  | MessageOutputEntry;

/**
 * Retrieve all entries in a conversation.
 */
export type ConversationHistory = {
  object: "conversation.history";
  conversationId: string;
  entries: Array<
    | AgentHandoffEntry
    | FunctionCallEntry
    | MessageInputEntry
    | FunctionResultEntry
    | ToolExecutionEntry
    | MessageOutputEntry
  >;
};

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

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

/** @internal */
export const ConversationHistory$inboundSchema: z.ZodType<
  ConversationHistory,
  unknown
> = z.object({
  object: z.literal("conversation.history").default("conversation.history"),
  conversation_id: z.string(),
  entries: z.array(
    smartUnion([
      AgentHandoffEntry$inboundSchema,
      FunctionCallEntry$inboundSchema,
      MessageInputEntry$inboundSchema,
      FunctionResultEntry$inboundSchema,
      ToolExecutionEntry$inboundSchema,
      MessageOutputEntry$inboundSchema,
    ]),
  ),
}).transform((v) => {
  return remap$(v, {
    "conversation_id": "conversationId",
  });
});

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