/*
 * 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 { ClosedEnum } from "../../types/enums.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

export const FunctionCallEventConfirmationStatus = {
  Pending: "pending",
  Allowed: "allowed",
  Denied: "denied",
} as const;
export type FunctionCallEventConfirmationStatus = ClosedEnum<
  typeof FunctionCallEventConfirmationStatus
>;

export type FunctionCallEvent = {
  type?: "function.call.delta" | undefined;
  createdAt?: Date | undefined;
  outputIndex: number | undefined;
  id: string;
  name: string;
  toolCallId: string;
  arguments: string;
  confirmationStatus?: FunctionCallEventConfirmationStatus | null | undefined;
};

/** @internal */
export const FunctionCallEventConfirmationStatus$inboundSchema: z.ZodNativeEnum<
  typeof FunctionCallEventConfirmationStatus
> = z.nativeEnum(FunctionCallEventConfirmationStatus);

/** @internal */
export const FunctionCallEvent$inboundSchema: z.ZodType<
  FunctionCallEvent,
  z.ZodTypeDef,
  unknown
> = z.object({
  type: z.literal("function.call.delta").default("function.call.delta"),
  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.string(),
  tool_call_id: z.string(),
  arguments: z.string(),
  confirmation_status: z.nullable(
    FunctionCallEventConfirmationStatus$inboundSchema,
  ).optional(),
}).transform((v) => {
  return remap$(v, {
    "created_at": "createdAt",
    "output_index": "outputIndex",
    "tool_call_id": "toolCallId",
    "confirmation_status": "confirmationStatus",
  });
});

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