/*
 * 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 {
  MessageInputContentChunks,
  MessageInputContentChunks$inboundSchema,
  MessageInputContentChunks$Outbound,
  MessageInputContentChunks$outboundSchema,
} from "./messageinputcontentchunks.js";

export const Role = {
  Assistant: "assistant",
  User: "user",
} as const;
export type Role = ClosedEnum<typeof Role>;

export type MessageInputEntryContent =
  | string
  | Array<MessageInputContentChunks>;

/**
 * Representation of an input message inside the conversation.
 */
export type MessageInputEntry = {
  object?: "entry" | undefined;
  type?: "message.input" | undefined;
  createdAt?: Date | undefined;
  completedAt?: Date | null | undefined;
  id?: string | undefined;
  role: Role;
  content: string | Array<MessageInputContentChunks>;
  prefix?: boolean | undefined;
};

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

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

/** @internal */
export const MessageInputEntryContent$outboundSchema: z.ZodType<
  MessageInputEntryContent$Outbound,
  z.ZodTypeDef,
  MessageInputEntryContent
> = z.union([z.string(), z.array(MessageInputContentChunks$outboundSchema)]);

export function messageInputEntryContentToJSON(
  messageInputEntryContent: MessageInputEntryContent,
): string {
  return JSON.stringify(
    MessageInputEntryContent$outboundSchema.parse(messageInputEntryContent),
  );
}
export function messageInputEntryContentFromJSON(
  jsonString: string,
): SafeParseResult<MessageInputEntryContent, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => MessageInputEntryContent$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'MessageInputEntryContent' from JSON`,
  );
}

/** @internal */
export const MessageInputEntry$inboundSchema: z.ZodType<
  MessageInputEntry,
  z.ZodTypeDef,
  unknown
> = z.object({
  object: z.literal("entry").default("entry"),
  type: z.literal("message.input").default("message.input"),
  created_at: z.string().datetime({ offset: true }).transform(v => new Date(v))
    .optional(),
  completed_at: z.nullable(
    z.string().datetime({ offset: true }).transform(v => new Date(v)),
  ).optional(),
  id: z.string().optional(),
  role: Role$inboundSchema,
  content: z.union([
    z.string(),
    z.array(MessageInputContentChunks$inboundSchema),
  ]),
  prefix: z.boolean().default(false),
}).transform((v) => {
  return remap$(v, {
    "created_at": "createdAt",
    "completed_at": "completedAt",
  });
});
/** @internal */
export type MessageInputEntry$Outbound = {
  object: "entry";
  type: "message.input";
  created_at?: string | undefined;
  completed_at?: string | null | undefined;
  id?: string | undefined;
  role: string;
  content: string | Array<MessageInputContentChunks$Outbound>;
  prefix: boolean;
};

/** @internal */
export const MessageInputEntry$outboundSchema: z.ZodType<
  MessageInputEntry$Outbound,
  z.ZodTypeDef,
  MessageInputEntry
> = z.object({
  object: z.literal("entry").default("entry" as const),
  type: z.literal("message.input").default("message.input" as const),
  createdAt: z.date().transform(v => v.toISOString()).optional(),
  completedAt: z.nullable(z.date().transform(v => v.toISOString())).optional(),
  id: z.string().optional(),
  role: Role$outboundSchema,
  content: z.union([
    z.string(),
    z.array(MessageInputContentChunks$outboundSchema),
  ]),
  prefix: z.boolean().default(false),
}).transform((v) => {
  return remap$(v, {
    createdAt: "created_at",
    completedAt: "completed_at",
  });
});

export function messageInputEntryToJSON(
  messageInputEntry: MessageInputEntry,
): string {
  return JSON.stringify(
    MessageInputEntry$outboundSchema.parse(messageInputEntry),
  );
}
export function messageInputEntryFromJSON(
  jsonString: string,
): SafeParseResult<MessageInputEntry, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => MessageInputEntry$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'MessageInputEntry' from JSON`,
  );
}
