"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveOpenAICompatProfileConfig = exports.isOpenAICompatProvider = void 0;
const droid_provider_1 = require("../targets/droid-provider");
function isOpenAICompatProvider(provider) {
    return provider === 'openai' || provider === 'generic-chat-completion-api';
}
exports.isOpenAICompatProvider = isOpenAICompatProvider;
function resolveOpenAICompatProfileConfig(profileName, settingsPath, env) {
    const baseUrl = env.ANTHROPIC_BASE_URL?.trim() || '';
    const apiKey = env.ANTHROPIC_AUTH_TOKEN?.trim() || env.ANTHROPIC_API_KEY?.trim() || '';
    if (!baseUrl || !apiKey) {
        return null;
    }
    const providerFromUrl = (0, droid_provider_1.inferDroidProviderFromBaseUrl)(baseUrl);
    const provider = isOpenAICompatProvider(providerFromUrl)
        ? providerFromUrl
        : (0, droid_provider_1.resolveDroidProvider)({
            provider: env.CCS_DROID_PROVIDER,
            baseUrl,
            model: env.ANTHROPIC_MODEL,
        });
    if (!isOpenAICompatProvider(provider)) {
        return null;
    }
    return {
        profileName,
        settingsPath,
        baseUrl,
        apiKey,
        provider,
        insecure: env.CCS_OPENAI_PROXY_INSECURE === '1' ||
            env.CCS_OPENAI_PROXY_INSECURE?.toLowerCase() === 'true',
        model: env.ANTHROPIC_MODEL?.trim() || undefined,
        opusModel: env.ANTHROPIC_DEFAULT_OPUS_MODEL?.trim() || undefined,
        sonnetModel: env.ANTHROPIC_DEFAULT_SONNET_MODEL?.trim() || undefined,
        haikuModel: env.ANTHROPIC_DEFAULT_HAIKU_MODEL?.trim() ||
            env.ANTHROPIC_SMALL_FAST_MODEL?.trim() ||
            undefined,
    };
}
exports.resolveOpenAICompatProfileConfig = resolveOpenAICompatProfileConfig;
//# sourceMappingURL=profile-router.js.map