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

import * as z from "zod/v4";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import * as openEnums from "../../types/enums.js";
import { OpenEnum } from "../../types/enums.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { smartUnion } from "../../types/smartUnion.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 = OpenEnum<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.ZodType<Role, unknown> = openEnums
  .inboundSchema(Role);
/** @internal */
export const Role$outboundSchema: z.ZodType<string, Role> = openEnums
  .outboundSchema(Role);

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

/** @internal */
export const MessageInputEntryContent$outboundSchema: z.ZodType<
  MessageInputEntryContent$Outbound,
  MessageInputEntryContent
> = smartUnion([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,
  unknown
> = z.object({
  object: z.literal("entry").default("entry"),
  type: z.literal("message.input").default("message.input"),
  created_at: z.iso.datetime({ offset: true }).transform(v => new Date(v))
    .optional(),
  completed_at: z.nullable(
    z.iso.datetime({ offset: true }).transform(v => new Date(v)),
  ).optional(),
  id: z.string().optional(),
  role: Role$inboundSchema,
  content: smartUnion([
    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,
  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: smartUnion([
    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`,
  );
}
