import { z } from "zod";
import { ConnectionIdPropertySchema, ConnectionPropertySchema, AuthenticationIdPropertySchema, } from "../../types/properties";
// Schemas for fetch function parameters
export const FetchUrlSchema = z
    .union([z.string(), z.instanceof(URL)])
    .describe("The full URL of the API endpoint to call (proxied through Zapier's Relay service)");
export const FetchInitZapierFieldsSchema = z.object({
    connectionId: ConnectionIdPropertySchema.optional().meta({
        deprecated: true,
    }),
    connection: ConnectionPropertySchema.optional(),
    /** @deprecated Use connection instead */
    authenticationId: AuthenticationIdPropertySchema.optional().meta({
        deprecated: true,
    }),
    callbackUrl: z
        .string()
        .optional()
        .describe("URL to send async response to (makes request async)"),
    maxTime: z
        .number()
        .int()
        .positive()
        .optional()
        .describe("Maximum seconds to wait for a response. Honored on a best-effort basis; the server may silently enforce a lower ceiling."),
});
export const FetchInitSchema = z
    .object({
    method: z
        .enum(["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"])
        .optional()
        .describe("HTTP method for the request (defaults to GET)"),
    headers: z
        .record(z.string(), z.string())
        .optional()
        .describe("HTTP headers to include in the request"),
    body: z
        .union([
        z.string(),
        z.instanceof(FormData),
        z.instanceof(URLSearchParams),
        z.record(z.string(), z.unknown()),
    ])
        .optional()
        .describe("Request body — plain objects and JSON strings are auto-detected and Content-Type is set accordingly"),
})
    .extend(FetchInitZapierFieldsSchema.shape)
    .optional()
    .describe("Request options including method, headers, body, and authentication")
    .meta({
    aliases: { connectionId: "connection", authenticationId: "connection" },
});
