/*
 * 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 { safeParse } from "../../lib/schemas.js";
import { ClosedEnum } from "../../types/enums.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  MessageEntries,
  MessageEntries$inboundSchema,
} from "./messageentries.js";

export const ConversationMessagesObject = {
  ConversationMessages: "conversation.messages",
} as const;
export type ConversationMessagesObject = ClosedEnum<
  typeof ConversationMessagesObject
>;

/**
 * Similar to the conversation history but only keep the messages
 */
export type ConversationMessages = {
  object: ConversationMessagesObject | undefined;
  conversationId: string;
  messages: Array<MessageEntries>;
};

/** @internal */
export const ConversationMessagesObject$inboundSchema: z.ZodNativeEnum<
  typeof ConversationMessagesObject
> = z.nativeEnum(ConversationMessagesObject);

/** @internal */
export const ConversationMessages$inboundSchema: z.ZodType<
  ConversationMessages,
  z.ZodTypeDef,
  unknown
> = z.object({
  object: ConversationMessagesObject$inboundSchema.default(
    "conversation.messages",
  ),
  conversation_id: z.string(),
  messages: z.array(MessageEntries$inboundSchema),
}).transform((v) => {
  return remap$(v, {
    "conversation_id": "conversationId",
  });
});

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