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

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

export type ToolExecutionDeltaEventName = BuiltInConnectors | string;

export type ToolExecutionDeltaEvent = {
  type: "tool.execution.delta";
  createdAt?: Date | undefined;
  outputIndex: number;
  id: string;
  name: BuiltInConnectors | string;
  arguments: string;
};

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

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

/** @internal */
export const ToolExecutionDeltaEvent$inboundSchema: z.ZodType<
  ToolExecutionDeltaEvent,
  unknown
> = z.object({
  type: z.literal("tool.execution.delta"),
  created_at: z.iso.datetime({ offset: true }).transform(v => new Date(v))
    .optional(),
  output_index: z.int().default(0),
  id: z.string(),
  name: smartUnion([BuiltInConnectors$inboundSchema, z.string()]),
  arguments: z.string(),
}).transform((v) => {
  return remap$(v, {
    "created_at": "createdAt",
    "output_index": "outputIndex",
  });
});

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