/*
 * 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 FunctionCallEventType = {
  FunctionCallDelta: "function.call.delta",
} as const;
export type FunctionCallEventType = ClosedEnum<typeof FunctionCallEventType>;

export type FunctionCallEvent = {
  type: FunctionCallEventType | undefined;
  createdAt?: Date | undefined;
  outputIndex: number | undefined;
  id: string;
  name: string;
  toolCallId: string;
  arguments: string;
};

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

/** @internal */
export const FunctionCallEvent$inboundSchema: z.ZodType<
  FunctionCallEvent,
  z.ZodTypeDef,
  unknown
> = z.object({
  type: FunctionCallEventType$inboundSchema.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(),
}).transform((v) => {
  return remap$(v, {
    "created_at": "createdAt",
    "output_index": "outputIndex",
    "tool_call_id": "toolCallId",
  });
});

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