/*
 * 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 { ClosedEnum } from "../../types/enums.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  OutputContentChunks,
  OutputContentChunks$inboundSchema,
} from "./outputcontentchunks.js";

export const MessageOutputEventType = {
  MessageOutputDelta: "message.output.delta",
} as const;
export type MessageOutputEventType = ClosedEnum<typeof MessageOutputEventType>;

export const MessageOutputEventRole = {
  Assistant: "assistant",
} as const;
export type MessageOutputEventRole = ClosedEnum<typeof MessageOutputEventRole>;

export type MessageOutputEventContent = string | OutputContentChunks;

export type MessageOutputEvent = {
  type: MessageOutputEventType | undefined;
  createdAt?: Date | undefined;
  outputIndex: number | undefined;
  id: string;
  contentIndex: number | undefined;
  model?: string | null | undefined;
  agentId?: string | null | undefined;
  role: MessageOutputEventRole | undefined;
  content: string | OutputContentChunks;
};

/** @internal */
export const MessageOutputEventType$inboundSchema: z.ZodNativeEnum<
  typeof MessageOutputEventType
> = z.nativeEnum(MessageOutputEventType);

/** @internal */
export const MessageOutputEventRole$inboundSchema: z.ZodNativeEnum<
  typeof MessageOutputEventRole
> = z.nativeEnum(MessageOutputEventRole);

/** @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: MessageOutputEventType$inboundSchema.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: MessageOutputEventRole$inboundSchema.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`,
  );
}
