"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.StatusCommand = void 0;
const chalk_1 = __importDefault(require("chalk"));
const processManager_1 = require("../utils/processManager");
const configManager_1 = require("../config/configManager");
class StatusCommand {
    processManager;
    configManager;
    constructor() {
        this.processManager = new processManager_1.ProcessManager();
        this.configManager = new configManager_1.ConfigManager();
    }
    async execute() {
        console.log(chalk_1.default.blue('📊 One Logger Status'));
        console.log(chalk_1.default.gray('='.repeat(50)));
        const serverPort = this.configManager.getServerPort();
        const webPort = this.configManager.getWebPort();
        // Check server status
        const serverRunning = await this.processManager.isPortInUse(serverPort);
        const serverStatus = serverRunning ?
            chalk_1.default.green('✅ Running') :
            chalk_1.default.red('❌ Stopped');
        console.log(`${chalk_1.default.cyan('API Server:')}\t\t${serverStatus}`);
        if (serverRunning) {
            console.log(`${chalk_1.default.gray('  URL:')}\t\t\thttp://localhost:${serverPort}`);
        }
        // Check web UI status
        const webRunning = await this.processManager.isPortInUse(webPort);
        const webStatus = webRunning ?
            chalk_1.default.green('✅ Running') :
            chalk_1.default.red('❌ Stopped');
        console.log(`${chalk_1.default.cyan('Web UI:')}\t\t${webStatus}`);
        if (webRunning) {
            console.log(`${chalk_1.default.gray('  URL:')}\t\t\thttp://localhost:${webPort}`);
        }
        // Overall status
        console.log(chalk_1.default.gray('='.repeat(50)));
        if (serverRunning && webRunning) {
            console.log(chalk_1.default.green('🎉 One Logger is fully operational'));
        }
        else if (serverRunning) {
            console.log(chalk_1.default.yellow('⚠️  One Logger is partially running (server only)'));
        }
        else {
            console.log(chalk_1.default.red('🔴 One Logger is not running'));
            console.log(chalk_1.default.gray('Run "one-logger start" to start the services'));
        }
        // Show managed processes
        const managedProcesses = this.processManager.getProcessList();
        if (managedProcesses.length > 0) {
            console.log(chalk_1.default.gray('\nManaged Processes:'));
            managedProcesses.forEach(process => {
                const status = process.killed ?
                    chalk_1.default.red('❌ Stopped') :
                    chalk_1.default.green('✅ Running');
                console.log(`  ${chalk_1.default.cyan(process.name)}:\t${status}`);
            });
        }
        // Show configuration
        console.log(chalk_1.default.gray('\nConfiguration:'));
        console.log(`  ${chalk_1.default.cyan('Server Port:')}\t${serverPort}`);
        console.log(`  ${chalk_1.default.cyan('Web Port:')}\t\t${webPort}`);
        console.log(`  ${chalk_1.default.cyan('Database:')}\t\t${this.configManager.getDatabasePath()}`);
    }
}
exports.StatusCommand = StatusCommand;
//# sourceMappingURL=status.js.map