/**
 * Gateway Self-Management Tool
 *
 * Provides self-management capabilities for the gateway including
 * status monitoring, configuration, health checks, and restart.
 */
import { logger } from '../utils/logger.js';
// ============================================================================
// GatewayTool
// ============================================================================
export class GatewayTool {
    static instance = null;
    running = false;
    startTime = 0;
    version = '0.1.16';
    channelCount = 0;
    agentCount = 1;
    sessionCount = 0;
    config = {};
    static getInstance() {
        if (!GatewayTool.instance) {
            GatewayTool.instance = new GatewayTool();
        }
        return GatewayTool.instance;
    }
    static resetInstance() {
        GatewayTool.instance = null;
    }
    start() {
        this.running = true;
        this.startTime = Date.now();
        logger.info('Gateway started');
    }
    getStatus() {
        return {
            running: this.running,
            uptime: this.getUptime(),
            version: this.version,
            channels: this.channelCount,
            agents: this.agentCount,
            sessions: this.sessionCount,
            memoryUsage: process.memoryUsage?.()?.heapUsed || 0,
        };
    }
    restart() {
        logger.info('Restarting gateway');
        this.running = true;
        this.startTime = Date.now();
    }
    getConfig() {
        return { ...this.config };
    }
    updateConfig(key, value) {
        logger.info(`Updating gateway config: ${key}`);
        this.config[key] = value;
    }
    getVersion() {
        return this.version;
    }
    getUptime() {
        if (!this.running || this.startTime === 0) {
            return 0;
        }
        return Math.floor((Date.now() - this.startTime) / 1000);
    }
    getChannelCount() {
        return this.channelCount;
    }
    setChannelCount(count) {
        this.channelCount = count;
    }
    getSessionCount() {
        return this.sessionCount;
    }
    setSessionCount(count) {
        this.sessionCount = count;
    }
    healthCheck() {
        logger.info('Running gateway health check');
        return {
            healthy: this.running,
            checks: {
                api: this.running,
                database: true,
                llm: true,
                channels: this.channelCount > 0 || true,
                memory: true,
            },
        };
    }
}
//# sourceMappingURL=gateway-tool.js.map