/*
 * 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 { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  MessageOutputContentChunks,
  MessageOutputContentChunks$inboundSchema,
  MessageOutputContentChunks$Outbound,
  MessageOutputContentChunks$outboundSchema,
} from "./messageoutputcontentchunks.js";

export type MessageOutputEntryContent =
  | string
  | Array<MessageOutputContentChunks>;

export type MessageOutputEntry = {
  object?: "entry" | undefined;
  type?: "message.output" | undefined;
  createdAt?: Date | undefined;
  completedAt?: Date | null | undefined;
  id?: string | undefined;
  agentId?: string | null | undefined;
  model?: string | null | undefined;
  role?: "assistant" | undefined;
  content: string | Array<MessageOutputContentChunks>;
};

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

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

export function messageOutputEntryContentToJSON(
  messageOutputEntryContent: MessageOutputEntryContent,
): string {
  return JSON.stringify(
    MessageOutputEntryContent$outboundSchema.parse(messageOutputEntryContent),
  );
}
export function messageOutputEntryContentFromJSON(
  jsonString: string,
): SafeParseResult<MessageOutputEntryContent, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => MessageOutputEntryContent$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'MessageOutputEntryContent' from JSON`,
  );
}

/** @internal */
export const MessageOutputEntry$inboundSchema: z.ZodType<
  MessageOutputEntry,
  z.ZodTypeDef,
  unknown
> = z.object({
  object: z.literal("entry").default("entry"),
  type: z.literal("message.output").default("message.output"),
  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(),
  agent_id: z.nullable(z.string()).optional(),
  model: z.nullable(z.string()).optional(),
  role: z.literal("assistant").default("assistant"),
  content: z.union([
    z.string(),
    z.array(MessageOutputContentChunks$inboundSchema),
  ]),
}).transform((v) => {
  return remap$(v, {
    "created_at": "createdAt",
    "completed_at": "completedAt",
    "agent_id": "agentId",
  });
});
/** @internal */
export type MessageOutputEntry$Outbound = {
  object: "entry";
  type: "message.output";
  created_at?: string | undefined;
  completed_at?: string | null | undefined;
  id?: string | undefined;
  agent_id?: string | null | undefined;
  model?: string | null | undefined;
  role: "assistant";
  content: string | Array<MessageOutputContentChunks$Outbound>;
};

/** @internal */
export const MessageOutputEntry$outboundSchema: z.ZodType<
  MessageOutputEntry$Outbound,
  z.ZodTypeDef,
  MessageOutputEntry
> = z.object({
  object: z.literal("entry").default("entry" as const),
  type: z.literal("message.output").default("message.output" as const),
  createdAt: z.date().transform(v => v.toISOString()).optional(),
  completedAt: z.nullable(z.date().transform(v => v.toISOString())).optional(),
  id: z.string().optional(),
  agentId: z.nullable(z.string()).optional(),
  model: z.nullable(z.string()).optional(),
  role: z.literal("assistant").default("assistant" as const),
  content: z.union([
    z.string(),
    z.array(MessageOutputContentChunks$outboundSchema),
  ]),
}).transform((v) => {
  return remap$(v, {
    createdAt: "created_at",
    completedAt: "completed_at",
    agentId: "agent_id",
  });
});

export function messageOutputEntryToJSON(
  messageOutputEntry: MessageOutputEntry,
): string {
  return JSON.stringify(
    MessageOutputEntry$outboundSchema.parse(messageOutputEntry),
  );
}
export function messageOutputEntryFromJSON(
  jsonString: string,
): SafeParseResult<MessageOutputEntry, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => MessageOutputEntry$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'MessageOutputEntry' from JSON`,
  );
}
