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

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 {
  OutputContentChunks,
  OutputContentChunks$inboundSchema,
} from "./outputcontentchunks.js";

export type MessageOutputEventContent = string | OutputContentChunks;

export type MessageOutputEvent = {
  type: "message.output.delta";
  createdAt?: Date | undefined;
  outputIndex: number;
  id: string;
  contentIndex: number;
  model?: string | null | undefined;
  agentId?: string | null | undefined;
  role: "assistant";
  content: string | OutputContentChunks;
};

/** @internal */
export const MessageOutputEventContent$inboundSchema: z.ZodType<
  MessageOutputEventContent,
  unknown
> = smartUnion([z.string(), OutputContentChunks$inboundSchema]);

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

/** @internal */
export const MessageOutputEvent$inboundSchema: z.ZodType<
  MessageOutputEvent,
  unknown
> = z.object({
  type: z.literal("message.output.delta"),
  created_at: z.iso.datetime({ offset: true }).transform(v => new Date(v))
    .optional(),
  output_index: z.int().default(0),
  id: z.string(),
  content_index: z.int().default(0),
  model: z.nullable(z.string()).optional(),
  agent_id: z.nullable(z.string()).optional(),
  role: z.literal("assistant").default("assistant"),
  content: smartUnion([z.string(), OutputContentChunks$inboundSchema]),
}).transform((v) => {
  return remap$(v, {
    "created_at": "createdAt",
    "output_index": "outputIndex",
    "content_index": "contentIndex",
    "agent_id": "agentId",
  });
});

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