"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createStatusCommand = createStatusCommand;
const kleur_1 = require("kleur");
const docker_compose_1 = require("../services/docker-compose");
const docker_network_1 = require("../services/docker-network");
const ssh_manager_1 = require("../services/ssh-manager");
const docker_volume_1 = require("../services/docker-volume");
const env_loader_1 = require("../utils/env-loader");
const logger_1 = require("../utils/logger");
const i18n_1 = require("../i18n");
const command_1 = require("../utils/command");
function indicator(active) {
    return active ? (0, kleur_1.green)('running') : (0, kleur_1.red)('stopped');
}
function createStatusCommand() {
    return (0, command_1.createCommand)('status')
        .description((0, i18n_1.t)('commands.status.description'))
        .action(() => {
        try {
            const config = env_loader_1.envLoader.load();
            logger_1.logger.info('Docker containers');
            try {
                const containers = docker_compose_1.composeService.ps(config.COMPOSE_FILE_PATH);
                if (containers.length === 0) {
                    console.log('  No containers found.');
                }
                else {
                    for (const container of containers) {
                        console.log(`  ${indicator(container.State === 'running')} ${container.Name} ${container.Status}`);
                    }
                }
            }
            catch (error) {
                console.log(`  ${(0, kleur_1.red)('Error:')} ${error instanceof Error ? error.message : String(error)}`);
            }
            logger_1.logger.info('SSH keys');
            const keys = ssh_manager_1.sshManager.listKeys(config.SSH_VOLUME_NAME);
            if (keys.length === 0) {
                console.log('  No injected SSH keys found.');
            }
            else {
                keys.forEach((key) => console.log(`  ${(0, kleur_1.green)('+')} ${key}`));
            }
            logger_1.logger.info('Docker network');
            console.log(`  ${indicator(docker_network_1.networkService.exists(config.NETWORK_NAME))} ${config.NETWORK_NAME}`);
            logger_1.logger.info('Docker volume');
            console.log(`  ${indicator(docker_volume_1.volumeService.exists(config.SSH_VOLUME_NAME))} ${config.SSH_VOLUME_NAME}`);
        }
        catch (error) {
            const message = error instanceof Error ? error.message : String(error);
            logger_1.logger.error(`Failed to get status: ${message}`);
            process.exit(1);
        }
    });
}
//# sourceMappingURL=status.js.map