"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.StopCommand = void 0;
const chalk_1 = __importDefault(require("chalk"));
const ora_1 = __importDefault(require("ora"));
const processManager_1 = require("../utils/processManager");
const serverManager_1 = require("../managers/serverManager");
const configManager_1 = require("../config/configManager");
class StopCommand {
    processManager;
    serverManager;
    configManager;
    constructor() {
        this.configManager = new configManager_1.ConfigManager();
        this.processManager = new processManager_1.ProcessManager();
        this.serverManager = new serverManager_1.ServerManager(this.configManager);
    }
    async execute() {
        console.log(chalk_1.default.blue('🛑 Stopping One Logger...'));
        const spinner = (0, ora_1.default)('Stopping services...').start();
        try {
            // Stop the server
            await this.serverManager.stop();
            // Kill all managed processes (web UI, etc.)
            await this.processManager.killAll();
            spinner.succeed(chalk_1.default.green('✅ One Logger stopped successfully'));
            console.log(chalk_1.default.gray('All services have been stopped.'));
        }
        catch (error) {
            spinner.fail(chalk_1.default.red('❌ Failed to stop One Logger'));
            if (error instanceof Error) {
                console.error(chalk_1.default.red('Error:'), error.message);
            }
            else {
                console.error(chalk_1.default.red('Unknown error occurred'));
            }
            throw error;
        }
    }
}
exports.StopCommand = StopCommand;
//# sourceMappingURL=stop.js.map