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

import * as z from "zod/v3";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  TextChunk,
  TextChunk$inboundSchema,
  TextChunk$Outbound,
  TextChunk$outboundSchema,
} from "./textchunk.js";
import {
  ToolReferenceChunk,
  ToolReferenceChunk$inboundSchema,
  ToolReferenceChunk$Outbound,
  ToolReferenceChunk$outboundSchema,
} from "./toolreferencechunk.js";

export type Thinking = ToolReferenceChunk | TextChunk;

export type ThinkChunk = {
  type?: "thinking" | undefined;
  thinking: Array<ToolReferenceChunk | TextChunk>;
  closed?: boolean | undefined;
};

/** @internal */
export const Thinking$inboundSchema: z.ZodType<
  Thinking,
  z.ZodTypeDef,
  unknown
> = z.union([ToolReferenceChunk$inboundSchema, TextChunk$inboundSchema]);
/** @internal */
export type Thinking$Outbound =
  | ToolReferenceChunk$Outbound
  | TextChunk$Outbound;

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

export function thinkingToJSON(thinking: Thinking): string {
  return JSON.stringify(Thinking$outboundSchema.parse(thinking));
}
export function thinkingFromJSON(
  jsonString: string,
): SafeParseResult<Thinking, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => Thinking$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'Thinking' from JSON`,
  );
}

/** @internal */
export const ThinkChunk$inboundSchema: z.ZodType<
  ThinkChunk,
  z.ZodTypeDef,
  unknown
> = z.object({
  type: z.literal("thinking").default("thinking"),
  thinking: z.array(
    z.union([ToolReferenceChunk$inboundSchema, TextChunk$inboundSchema]),
  ),
  closed: z.boolean().default(true),
});
/** @internal */
export type ThinkChunk$Outbound = {
  type: "thinking";
  thinking: Array<ToolReferenceChunk$Outbound | TextChunk$Outbound>;
  closed: boolean;
};

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

export function thinkChunkToJSON(thinkChunk: ThinkChunk): string {
  return JSON.stringify(ThinkChunk$outboundSchema.parse(thinkChunk));
}
export function thinkChunkFromJSON(
  jsonString: string,
): SafeParseResult<ThinkChunk, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ThinkChunk$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ThinkChunk' from JSON`,
  );
}
