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

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

export type ToolExecutionEntryName = BuiltInConnectors | string;

export type ToolExecutionEntry = {
  object?: "entry" | undefined;
  type?: "tool.execution" | undefined;
  createdAt?: Date | undefined;
  completedAt?: Date | null | undefined;
  agentId?: string | null | undefined;
  model?: string | null | undefined;
  id?: string | undefined;
  name: BuiltInConnectors | string;
  arguments: string;
  info?: { [k: string]: any } | undefined;
};

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

/** @internal */
export const ToolExecutionEntryName$outboundSchema: z.ZodType<
  ToolExecutionEntryName$Outbound,
  ToolExecutionEntryName
> = smartUnion([BuiltInConnectors$outboundSchema, z.string()]);

export function toolExecutionEntryNameToJSON(
  toolExecutionEntryName: ToolExecutionEntryName,
): string {
  return JSON.stringify(
    ToolExecutionEntryName$outboundSchema.parse(toolExecutionEntryName),
  );
}
export function toolExecutionEntryNameFromJSON(
  jsonString: string,
): SafeParseResult<ToolExecutionEntryName, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ToolExecutionEntryName$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ToolExecutionEntryName' from JSON`,
  );
}

/** @internal */
export const ToolExecutionEntry$inboundSchema: z.ZodType<
  ToolExecutionEntry,
  unknown
> = z.object({
  object: z.literal("entry").default("entry"),
  type: z.literal("tool.execution").default("tool.execution"),
  created_at: z.iso.datetime({ offset: true }).transform(v => new Date(v))
    .optional(),
  completed_at: z.nullable(
    z.iso.datetime({ offset: true }).transform(v => new Date(v)),
  ).optional(),
  agent_id: z.nullable(z.string()).optional(),
  model: z.nullable(z.string()).optional(),
  id: z.string().optional(),
  name: smartUnion([BuiltInConnectors$inboundSchema, z.string()]),
  arguments: z.string(),
  info: z.record(z.string(), z.any()).optional(),
}).transform((v) => {
  return remap$(v, {
    "created_at": "createdAt",
    "completed_at": "completedAt",
    "agent_id": "agentId",
  });
});
/** @internal */
export type ToolExecutionEntry$Outbound = {
  object: "entry";
  type: "tool.execution";
  created_at?: string | undefined;
  completed_at?: string | null | undefined;
  agent_id?: string | null | undefined;
  model?: string | null | undefined;
  id?: string | undefined;
  name: string | string;
  arguments: string;
  info?: { [k: string]: any } | undefined;
};

/** @internal */
export const ToolExecutionEntry$outboundSchema: z.ZodType<
  ToolExecutionEntry$Outbound,
  ToolExecutionEntry
> = z.object({
  object: z.literal("entry").default("entry" as const),
  type: z.literal("tool.execution").default("tool.execution" as const),
  createdAt: z.date().transform(v => v.toISOString()).optional(),
  completedAt: z.nullable(z.date().transform(v => v.toISOString())).optional(),
  agentId: z.nullable(z.string()).optional(),
  model: z.nullable(z.string()).optional(),
  id: z.string().optional(),
  name: smartUnion([BuiltInConnectors$outboundSchema, z.string()]),
  arguments: z.string(),
  info: z.record(z.string(), z.any()).optional(),
}).transform((v) => {
  return remap$(v, {
    createdAt: "created_at",
    completedAt: "completed_at",
    agentId: "agent_id",
  });
});

export function toolExecutionEntryToJSON(
  toolExecutionEntry: ToolExecutionEntry,
): string {
  return JSON.stringify(
    ToolExecutionEntry$outboundSchema.parse(toolExecutionEntry),
  );
}
export function toolExecutionEntryFromJSON(
  jsonString: string,
): SafeParseResult<ToolExecutionEntry, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ToolExecutionEntry$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ToolExecutionEntry' from JSON`,
  );
}
