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

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 ToolExecutionDoneEventName = BuiltInConnectors | string;

export type ToolExecutionDoneEvent = {
  type: "tool.execution.done";
  createdAt?: Date | undefined;
  outputIndex: number;
  id: string;
  name: BuiltInConnectors | string;
  info?: { [k: string]: any } | undefined;
};

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

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

/** @internal */
export const ToolExecutionDoneEvent$inboundSchema: z.ZodType<
  ToolExecutionDoneEvent,
  unknown
> = z.object({
  type: z.literal("tool.execution.done"),
  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()]),
  info: z.record(z.string(), z.any()).optional(),
}).transform((v) => {
  return remap$(v, {
    "created_at": "createdAt",
    "output_index": "outputIndex",
  });
});

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