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

export type ToolExecutionStartedEventName = BuiltInConnectors | string;

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

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

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

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

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