/*
 * 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";
import {
  FunctionCallEntryArguments,
  FunctionCallEntryArguments$inboundSchema,
  FunctionCallEntryArguments$Outbound,
  FunctionCallEntryArguments$outboundSchema,
} from "./functioncallentryarguments.js";

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

export type FunctionCallEntry = {
  object?: "entry" | undefined;
  type?: "function.call" | undefined;
  createdAt?: Date | undefined;
  completedAt?: Date | null | undefined;
  id?: string | undefined;
  toolCallId: string;
  name: string;
  arguments: FunctionCallEntryArguments;
  confirmationStatus?: ConfirmationStatus | null | undefined;
};

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

/** @internal */
export const FunctionCallEntry$inboundSchema: z.ZodType<
  FunctionCallEntry,
  z.ZodTypeDef,
  unknown
> = z.object({
  object: z.literal("entry").default("entry"),
  type: z.literal("function.call").default("function.call"),
  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(),
  tool_call_id: z.string(),
  name: z.string(),
  arguments: FunctionCallEntryArguments$inboundSchema,
  confirmation_status: z.nullable(ConfirmationStatus$inboundSchema).optional(),
}).transform((v) => {
  return remap$(v, {
    "created_at": "createdAt",
    "completed_at": "completedAt",
    "tool_call_id": "toolCallId",
    "confirmation_status": "confirmationStatus",
  });
});
/** @internal */
export type FunctionCallEntry$Outbound = {
  object: "entry";
  type: "function.call";
  created_at?: string | undefined;
  completed_at?: string | null | undefined;
  id?: string | undefined;
  tool_call_id: string;
  name: string;
  arguments: FunctionCallEntryArguments$Outbound;
  confirmation_status?: string | null | undefined;
};

/** @internal */
export const FunctionCallEntry$outboundSchema: z.ZodType<
  FunctionCallEntry$Outbound,
  z.ZodTypeDef,
  FunctionCallEntry
> = z.object({
  object: z.literal("entry").default("entry" as const),
  type: z.literal("function.call").default("function.call" as const),
  createdAt: z.date().transform(v => v.toISOString()).optional(),
  completedAt: z.nullable(z.date().transform(v => v.toISOString())).optional(),
  id: z.string().optional(),
  toolCallId: z.string(),
  name: z.string(),
  arguments: FunctionCallEntryArguments$outboundSchema,
  confirmationStatus: z.nullable(ConfirmationStatus$outboundSchema).optional(),
}).transform((v) => {
  return remap$(v, {
    createdAt: "created_at",
    completedAt: "completed_at",
    toolCallId: "tool_call_id",
    confirmationStatus: "confirmation_status",
  });
});

export function functionCallEntryToJSON(
  functionCallEntry: FunctionCallEntry,
): string {
  return JSON.stringify(
    FunctionCallEntry$outboundSchema.parse(functionCallEntry),
  );
}
export function functionCallEntryFromJSON(
  jsonString: string,
): SafeParseResult<FunctionCallEntry, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => FunctionCallEntry$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'FunctionCallEntry' from JSON`,
  );
}
