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

export type Name = BuiltInConnectors | string;

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

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

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

export function nameToJSON(name: Name): string {
  return JSON.stringify(Name$outboundSchema.parse(name));
}
export function nameFromJSON(
  jsonString: string,
): SafeParseResult<Name, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => Name$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'Name' from JSON`,
  );
}

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

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`,
  );
}
