/**
 * SDK-related types and interfaces
 */
import { z } from "zod";
import { CredentialsSchema } from "./credentials";
import { MAX_CONCURRENCY_LIMIT } from "../constants";
// SDK Configuration Types
export const BaseSdkOptionsSchema = z.object({
    credentials: CredentialsSchema.optional().describe("Authentication credentials. Can be a string (token or API key), a client credentials object ({ clientId, clientSecret }), a PKCE object ({ clientId }), or a function returning any of those."),
    debug: z.boolean().optional().describe("Enable debug logging."),
    baseUrl: z
        .string()
        .optional()
        .describe("Base URL for Zapier API endpoints.")
        .meta({ valueHint: "url" }),
    trackingBaseUrl: z
        .string()
        .optional()
        .describe("Base URL for Zapier tracking endpoints.")
        .meta({ valueHint: "url" }),
    /**
     * Maximum number of retries for rate-limited requests (429 responses).
     * Set to 0 to disable retries. Default is 3.
     */
    maxNetworkRetries: z
        .number()
        .optional()
        .describe("Max retries for rate-limited requests (default: 3).")
        .meta({ valueHint: "count" }),
    /**
     * Maximum delay in milliseconds to wait for a rate limit retry.
     * If the server requests a longer delay, the request fails immediately.
     * Default is 60000 (60 seconds).
     */
    maxNetworkRetryDelayMs: z
        .number()
        .optional()
        .describe("Max delay in ms to wait for retry (default: 60000).")
        .meta({ valueHint: "ms" }),
    /**
     * Maximum number of concurrent in-flight HTTP requests per client.
     * Requests beyond this limit queue in FIFO order until a slot frees.
     * Pass `Infinity` to disable. Default: 200.
     *
     * The description and meta are duplicated across the outer wrapper and
     * the inner numeric branch because the SDK and CLI doc generators walk
     * the schema differently — the SDK reader looks at wrappers only, while
     * the CLI reader recurses into union branches.
     */
    maxConcurrentRequests: z
        .union([
        z
            .number()
            .int()
            .min(1)
            .max(MAX_CONCURRENCY_LIMIT)
            .describe(`Max concurrent in-flight HTTP requests (default: 200, max: ${MAX_CONCURRENCY_LIMIT}).`)
            .meta({ valueHint: "count" }),
        z.literal(Infinity),
    ])
        .optional()
        .describe(`Max concurrent in-flight HTTP requests (default: 200, max: ${MAX_CONCURRENCY_LIMIT}).`)
        .meta({ valueHint: "count" }),
    approvalTimeoutMs: z
        .number()
        .optional()
        .describe("Timeout in ms for approval polling. Default: 600000 (10 min).")
        .meta({ valueHint: "ms" }),
    maxApprovalRetries: z
        .number()
        .optional()
        .describe("Maximum number of sequential approval rounds per request (one per gating policy) before giving up. Default: 2."),
    approvalMode: z
        .enum(["disabled", "poll", "throw"])
        .optional()
        .describe('Approval flow behavior. "poll" creates the approval, opens it in a browser, polls until resolved, and retries the original request. "throw" creates the approval and throws a ZapierApprovalError with the approval URL so the caller can surface it. "disabled" throws a ZapierApprovalError on approval-required responses without creating an approval. Resolution order is: explicit option, then ZAPIER_APPROVAL_MODE, then the default behavior (poll for interactive TTY, throw otherwise).'),
    // Internal
    manifestPath: z
        .string()
        .optional()
        .describe("Path to a .zapierrc manifest file for app version locking.")
        .meta({ internal: true }),
    manifest: z
        .custom()
        .optional()
        .describe("Manifest for app version locking.")
        .meta({ internal: true }),
    onEvent: z.custom().optional().meta({ internal: true }),
    fetch: z.custom().optional().meta({ internal: true }),
    eventEmission: z
        .custom()
        .optional()
        .meta({ internal: true }),
    callerPackage: z
        .custom()
        .optional()
        .meta({ internal: true }),
    cache: z.custom().optional().meta({ internal: true }),
    canIncludeSharedConnections: z
        .boolean()
        .optional()
        .describe("Allow listing shared connections."),
    canIncludeSharedTables: z
        .boolean()
        .optional()
        .describe("Allow listing shared tables."),
    canDeleteTables: z.boolean().optional().describe("Allow deleting tables."),
    // Deprecated
    token: z.string().optional().meta({ deprecated: true }), // Use credentials instead
});
