/**
 * @license
 * Copyright 2025 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */
/**
 * Manages the registration and discovery of AI providers
 */
export class ProviderRegistry {
    providers = new Map();
    configs = new Map();
    /**
     * Register a provider instance
     */
    register(provider) {
        this.providers.set(provider.name, provider);
    }
    /**
     * Register a provider configuration
     */
    registerConfig(config) {
        this.configs.set(config.name, config);
    }
    /**
     * Get a provider by name
     */
    getProvider(name) {
        return this.providers.get(name);
    }
    /**
     * Get provider configuration
     */
    getConfig(name) {
        return this.configs.get(name);
    }
    /**
     * Get all available provider names
     */
    getAvailableProviders() {
        return Array.from(this.providers.keys());
    }
    /**
     * Get all enabled providers sorted by priority
     */
    getEnabledProviders() {
        const enabledProviders = Array.from(this.providers.entries())
            .filter(([name]) => {
            const config = this.configs.get(name);
            return config?.enabled !== false;
        })
            .map(([, provider]) => provider);
        // Sort by priority (lower number = higher priority)
        return enabledProviders.sort((a, b) => {
            const aConfig = this.configs.get(a.name);
            const bConfig = this.configs.get(b.name);
            return (aConfig?.priority || 999) - (bConfig?.priority || 999);
        });
    }
    /**
     * Get the default provider (highest priority enabled provider)
     */
    getDefaultProvider() {
        const enabledProviders = this.getEnabledProviders();
        return enabledProviders[0];
    }
    /**
     * Check if a provider is available and enabled
     */
    isProviderAvailable(name) {
        const provider = this.providers.get(name);
        const config = this.configs.get(name);
        return provider !== undefined && config?.enabled !== false;
    }
    /**
     * Remove a provider
     */
    unregister(name) {
        this.providers.delete(name);
        this.configs.delete(name);
    }
    /**
     * Get usage statistics across all providers
     */
    async getUsageStats() {
        const stats = {};
        for (const [name, provider] of this.providers) {
            try {
                const limits = await provider.checkLimits();
                stats[name] = limits.currentUsage;
            }
            catch (error) {
                console.warn(`Failed to get usage stats for ${name}:`, error);
                stats[name] = undefined;
            }
        }
        return stats;
    }
}
//# sourceMappingURL=registry.js.map