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

export type MessageOutputEventContent = string | OutputContentChunks;

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

/** @internal */
export const MessageOutputEventContent$inboundSchema: z.ZodType<
  MessageOutputEventContent,
  z.ZodTypeDef,
  unknown
> = z.union([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,
  z.ZodTypeDef,
  unknown
> = z.object({
  type: z.literal("message.output.delta").default("message.output.delta"),
  created_at: z.string().datetime({ offset: true }).transform(v => new Date(v))
    .optional(),
  output_index: z.number().int().default(0),
  id: z.string(),
  content_index: z.number().int().default(0),
  model: z.nullable(z.string()).optional(),
  agent_id: z.nullable(z.string()).optional(),
  role: z.literal("assistant").default("assistant"),
  content: z.union([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`,
  );
}
