"use strict";
// =============================================================================
// Pure Agent - Platform Registry
// Ported from Hermes gateway/platform_registry.py
// =============================================================================
Object.defineProperty(exports, "__esModule", { value: true });
exports.platformRegistry = void 0;
const logger_1 = require("../logger");
// ---------------------------------------------------------------------------
// PlatformRegistry
// ---------------------------------------------------------------------------
class PlatformRegistry {
    _entries = new Map();
    register(entry) {
        this._entries.set(entry.name, entry);
        (0, logger_1.getLogger)().debug(`Registered platform adapter: ${entry.name}`);
    }
    get(name) {
        return this._entries.get(name);
    }
    createAdapter(platform, config) {
        const entry = this._entries.get(platform);
        if (!entry)
            return null;
        // Check dependencies
        if (entry.checkFn && !entry.checkFn()) {
            (0, logger_1.getLogger)().warn(`Platform ${platform}: dependencies not met. ${entry.installHint || ''}`);
            return null;
        }
        // Validate config
        if (entry.validateConfig && !entry.validateConfig(config)) {
            (0, logger_1.getLogger)().warn(`Platform ${platform}: invalid config`);
            return null;
        }
        try {
            return entry.factory(config);
        }
        catch (err) {
            (0, logger_1.getLogger)().error(`Platform ${platform}: failed to create adapter: ${err.message}`);
            return null;
        }
    }
    getAll() {
        return Array.from(this._entries.values());
    }
    has(name) {
        return this._entries.has(name);
    }
}
// Singleton
exports.platformRegistry = new PlatformRegistry();
//# sourceMappingURL=platform-registry.js.map