"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerProvider = registerProvider;
exports.getProvider = getProvider;
exports.listProviders = listProviders;
const logger_1 = require("../../../lib/logger");
const anthropic_1 = require("./anthropic");
const github_1 = require("./github");
const google_1 = require("./google");
const microsoft_1 = require("./microsoft");
const mock_1 = require("./mock");
const providers = new Map();
function registerProvider(cfg) {
    const handler = createHandler(cfg);
    providers.set(cfg.provider, handler);
    logger_1.loggerRegistry.info(`[oauth] registered provider: ${cfg.provider}`);
}
function getProvider(name) {
    return providers.get(name) ?? null;
}
function listProviders() {
    return Array.from(providers.values()).map((h) => ({
        provider: h.config.provider,
        name: h.config.displayName || capitalize(h.config.provider),
    }));
}
function createHandler(cfg) {
    const { provider } = cfg;
    switch (provider) {
        case 'google':
            return (0, google_1.createGoogleHandler)(cfg);
        case 'github':
            return (0, github_1.createGitHubHandler)(cfg);
        case 'microsoft':
            return (0, microsoft_1.createMicrosoftHandler)(cfg);
        case 'mock':
            return (0, mock_1.createMockHandler)(cfg);
        case 'anthropic':
            return (0, anthropic_1.createAnthropicHandler)(cfg);
        default:
            throw new Error(`Unsupported OAuth provider: ${provider}. Supported: google, github, microsoft, anthropic, mock`);
    }
}
function capitalize(s) {
    return s.charAt(0).toUpperCase() + s.slice(1);
}
