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

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

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

/** @internal */
export const ToolExecutionStartedEventName$inboundSchema: z.ZodType<
  ToolExecutionStartedEventName,
  unknown
> = smartUnion([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,
  unknown
> = z.object({
  type: z.literal("tool.execution.started"),
  created_at: z.iso.datetime({ offset: true }).transform(v => new Date(v))
    .optional(),
  output_index: z.int().default(0),
  id: z.string(),
  model: z.nullable(z.string()).optional(),
  agent_id: z.nullable(z.string()).optional(),
  name: smartUnion([BuiltInConnectors$inboundSchema, z.string()]),
  arguments: z.string(),
}).transform((v) => {
  return remap$(v, {
    "created_at": "createdAt",
    "output_index": "outputIndex",
    "agent_id": "agentId",
  });
});

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