import { z } from "zod";
import { createToolFactory, ToolCategory } from "../../tools2/types.js";
import { buildIntegrationDocumentation, getRelevantExamples, getSqlBestPractices, SQL_PLUGIN_MIN_VERSIONS_FOR_PARAMETERS, } from "./get-api-docs.js";
/**
 * Check if any of the provided integrations are SQL databases
 */
function hasSqlIntegrations(integrationIds, services) {
    const sqlPluginIds = new Set(Object.keys(SQL_PLUGIN_MIN_VERSIONS_FOR_PARAMETERS));
    for (const integrationId of integrationIds) {
        const header = services.integrationStore.getHeader(integrationId);
        if (header && sqlPluginIds.has(header.plugin.id)) {
            return true;
        }
    }
    return false;
}
/**
 * Pared-down tool that provides only dynamic integration-specific documentation.
 * Used when system skills are enabled - static documentation lives in skill files.
 */
export const getIntegrationTypesToolFactory = createToolFactory("getIntegrationTypes", (services) => ({
    category: ToolCategory.API,
    readOnly: true,
    description: `Get TypeScript type definitions and examples for specific integrations.

**When to call this tool:**
- BEFORE building or modifying APIs that use integrations
- After reading the API skill file, to get integration-specific TypeScript class definitions

**This tool provides:**
- TypeScript class definitions (constructor signatures, config options, methods)
- Integration-specific examples and patterns
- SQL parameterized query syntax (for database integrations, if supported)

**Note:** Core API documentation (scoping rules, control flow, best practices) is in the skill files.
This tool provides ONLY the dynamic, integration-specific information.`,
    inputSchema: z.object({
        integrationIds: z
            .array(z.string())
            .min(1)
            .describe("Integration IDs to get type definitions for. Pass the actual integration IDs from your page context."),
    }),
    execute: async ({ integrationIds }) => {
        const outputSections = [];
        // Add integration-specific TypeScript type definitions
        const integrationDocs = buildIntegrationDocumentation(integrationIds, services);
        if (integrationDocs) {
            outputSections.push(integrationDocs);
        }
        // Add SQL parameterized queries section if any SQL integrations are present
        if (hasSqlIntegrations(integrationIds, services)) {
            const sqlDocs = getSqlBestPractices({
                parameterizedApisEnabled: services.features.parameterizedApisEnabled,
                pluginExecutionVersions: services.integrationStore.pluginExecutionVersions,
            });
            outputSections.push(sqlDocs);
        }
        // Add relevant examples based on integration types
        const examples = getRelevantExamples(integrationIds, services);
        if (examples) {
            outputSections.push(examples);
        }
        return {
            documentation: outputSections.filter(Boolean).join("\n\n---\n\n"),
            integrationCount: integrationIds.length,
        };
    },
    getSummary: (input, output) => {
        const ids = input.integrationIds ?? [];
        return {
            input: `${ids.length} integration${ids.length === 1 ? "" : "s"}`,
            output: `${output.integrationCount ?? 0} type definition${(output.integrationCount ?? 0) === 1 ? "" : "s"}`,
        };
    },
}));
//# sourceMappingURL=get-integration-types.js.map