/**
 * @license
 * Copyright 2025 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */
import { createCodeAssistContentGenerator } from '../code_assist/codeAssist.js';
import { DEFAULT_GEMINI_MODEL } from '../config/models.js';
import { ProviderContentGenerator } from '../providers/ProviderContentGenerator.js';
import { GoogleGenAIWrapper } from './googleGenAIWrapper.js';
import { InstallationManager } from '../utils/installationManager.js';
export var AuthType;
(function (AuthType) {
    AuthType["LOGIN_WITH_GOOGLE"] = "oauth-personal";
    AuthType["USE_GEMINI"] = "gemini-api-key";
    AuthType["USE_VERTEX_AI"] = "vertex-ai";
    AuthType["CLOUD_SHELL"] = "cloud-shell";
    AuthType["USE_PROVIDER"] = "provider";
    AuthType["USE_NONE"] = "none";
    AuthType["OAUTH_GEMINI"] = "oauth_gemini";
    AuthType["OAUTH_QWEN"] = "oauth_qwen";
    AuthType["OAUTH_ANTHROPIC"] = "oauth_anthropic";
    // Generic auth types for runtime state (Phase 5)
    AuthType["API_KEY"] = "api-key";
    AuthType["OAUTH"] = "oauth";
})(AuthType || (AuthType = {}));
export function createContentGeneratorConfig(config, authType) {
    const geminiApiKey = process.env.GEMINI_API_KEY || undefined;
    const googleApiKey = process.env.GOOGLE_API_KEY || undefined;
    const googleCloudProject = process.env.GOOGLE_CLOUD_PROJECT || undefined;
    const googleCloudLocation = process.env.GOOGLE_CLOUD_LOCATION || undefined;
    // Use runtime model from config if available; otherwise, fall back to parameter or default
    const effectiveModel = config.getModel() || DEFAULT_GEMINI_MODEL;
    const contentGeneratorConfig = {
        model: effectiveModel,
        authType,
        proxy: config?.getProxy(),
    };
    // If we are using Google auth or we are in Cloud Shell, there is nothing else to validate for now
    if (authType === AuthType.LOGIN_WITH_GOOGLE ||
        authType === AuthType.CLOUD_SHELL) {
        return contentGeneratorConfig;
    }
    if (authType === AuthType.USE_GEMINI && geminiApiKey) {
        contentGeneratorConfig.apiKey = geminiApiKey;
        contentGeneratorConfig.vertexai = false;
        return contentGeneratorConfig;
    }
    if (authType === AuthType.USE_VERTEX_AI &&
        (googleApiKey || (googleCloudProject && googleCloudLocation))) {
        contentGeneratorConfig.apiKey = googleApiKey;
        contentGeneratorConfig.vertexai = true;
        return contentGeneratorConfig;
    }
    return contentGeneratorConfig;
}
export async function createContentGenerator(config, gcConfig, sessionId) {
    const version = process.env.CLI_VERSION || process.version;
    const httpOptions = {
        headers: {
            'User-Agent': `LLxprt-Code/${version} (${process.platform}; ${process.arch})`,
        },
    };
    // Always use provider path if a provider manager exists
    if (config.providerManager) {
        return new ProviderContentGenerator(config.providerManager, config);
    }
    if (config.authType === AuthType.LOGIN_WITH_GOOGLE ||
        config.authType === AuthType.CLOUD_SHELL) {
        return createCodeAssistContentGenerator(httpOptions, config.authType, gcConfig, sessionId);
    }
    if (config.authType === AuthType.USE_GEMINI ||
        config.authType === AuthType.USE_VERTEX_AI) {
        let headers = {};
        if (gcConfig?.getUsageStatisticsEnabled()) {
            const installationManager = new InstallationManager();
            const installationId = installationManager.getInstallationId();
            headers = {
                ...headers,
                'x-gemini-api-privileged-user-id': `${installationId}`,
            };
        }
        const httpOptions = { headers };
        return new GoogleGenAIWrapper(config, httpOptions);
    }
    throw new Error(`Error creating contentGenerator: Unsupported authType: ${config.authType}`);
}
//# sourceMappingURL=contentGenerator.js.map