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

import * as z from "zod/v3";
import { ClosedEnum } from "../../types/enums.js";
import {
  ReferenceChunk,
  ReferenceChunk$Outbound,
  ReferenceChunk$outboundSchema,
} from "./referencechunk.js";
import {
  TextChunk,
  TextChunk$Outbound,
  TextChunk$outboundSchema,
} from "./textchunk.js";

export type Thinking = ReferenceChunk | TextChunk;

export const ThinkChunkType = {
  Thinking: "thinking",
} as const;
export type ThinkChunkType = ClosedEnum<typeof ThinkChunkType>;

export type ThinkChunk = {
  thinking: Array<ReferenceChunk | TextChunk>;
  /**
   * Whether the thinking chunk is closed or not. Currently only used for prefixing.
   */
  closed?: boolean | undefined;
  type?: ThinkChunkType | undefined;
};

/** @internal */
export type Thinking$Outbound = ReferenceChunk$Outbound | TextChunk$Outbound;

/** @internal */
export const Thinking$outboundSchema: z.ZodType<
  Thinking$Outbound,
  z.ZodTypeDef,
  Thinking
> = z.union([ReferenceChunk$outboundSchema, TextChunk$outboundSchema]);

export function thinkingToJSON(thinking: Thinking): string {
  return JSON.stringify(Thinking$outboundSchema.parse(thinking));
}

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

/** @internal */
export type ThinkChunk$Outbound = {
  thinking: Array<ReferenceChunk$Outbound | TextChunk$Outbound>;
  closed?: boolean | undefined;
  type: string;
};

/** @internal */
export const ThinkChunk$outboundSchema: z.ZodType<
  ThinkChunk$Outbound,
  z.ZodTypeDef,
  ThinkChunk
> = z.object({
  thinking: z.array(
    z.union([ReferenceChunk$outboundSchema, TextChunk$outboundSchema]),
  ),
  closed: z.boolean().optional(),
  type: ThinkChunkType$outboundSchema.default("thinking"),
});

export function thinkChunkToJSON(thinkChunk: ThinkChunk): string {
  return JSON.stringify(ThinkChunk$outboundSchema.parse(thinkChunk));
}
