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

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 {
  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;
  agentId?: string | null | undefined;
  model?: string | null | undefined;
  id?: string | undefined;
  role?: "assistant" | undefined;
  content: string | Array<MessageOutputContentChunks>;
};

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

/** @internal */
export const MessageOutputEntryContent$outboundSchema: z.ZodType<
  MessageOutputEntryContent$Outbound,
  MessageOutputEntryContent
> = smartUnion([
  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,
  unknown
> = z.object({
  object: z.literal("entry").default("entry"),
  type: z.literal("message.output").default("message.output"),
  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(),
  agent_id: z.nullable(z.string()).optional(),
  model: z.nullable(z.string()).optional(),
  id: z.string().optional(),
  role: z.literal("assistant").default("assistant"),
  content: smartUnion([
    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;
  agent_id?: string | null | undefined;
  model?: string | null | undefined;
  id?: string | undefined;
  role: "assistant";
  content: string | Array<MessageOutputContentChunks$Outbound>;
};

/** @internal */
export const MessageOutputEntry$outboundSchema: z.ZodType<
  MessageOutputEntry$Outbound,
  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(),
  agentId: z.nullable(z.string()).optional(),
  model: z.nullable(z.string()).optional(),
  id: z.string().optional(),
  role: z.literal("assistant").default("assistant" as const),
  content: smartUnion([
    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`,
  );
}
