"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.uploadEnvironmentVariablesStep = void 0;
const telemetry_1 = require("../../telemetry");
const analytics_1 = require("../../utils/analytics");
const ui_1 = require("../../ui");
const vercel_1 = require("./providers/vercel");
const uploadEnvironmentVariablesStep = async (envVars, { integration, session, }) => {
    const providers = [
        new vercel_1.VercelEnvironmentProvider({ installDir: session.installDir }),
    ];
    let provider = null;
    for (const p of providers) {
        if (await p.detect()) {
            provider = p;
            break;
        }
    }
    if (!provider) {
        analytics_1.analytics.wizardCapture('env upload skipped', {
            reason: 'no environment provider found',
            integration,
        });
        return [];
    }
    // Auto-accept — the agent already wrote env vars via MCP tools
    (0, ui_1.getUI)().log.info(`Uploading environment variables to ${provider.name}...`);
    const results = await (0, telemetry_1.traceStep)('uploading environment variables', async () => {
        return await provider.uploadEnvVars(envVars);
    });
    analytics_1.analytics.wizardCapture('env uploaded', {
        provider: provider.name,
        integration,
    });
    return Object.keys(results).filter((key) => results[key]);
};
exports.uploadEnvironmentVariablesStep = uploadEnvironmentVariablesStep;
