"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var NodeService_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NodeService = void 0;
const common_1 = require("@nestjs/common");
const config_service_1 = require("../config/config.service");
const shell_service_1 = require("../shell/shell.service");
let NodeService = NodeService_1 = class NodeService {
    constructor(shellService, configService) {
        this.shellService = shellService;
        this.configService = configService;
    }
    listNodes() {
        return this.configService.config.nodes;
    }
    async addNode(dto) {
        try {
            const client = await this.shellService.createAndConnectClient(dto);
            client.connection.end();
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
        this.configService.config.nodes.push(dto);
        this.configService.saveConfig();
        this.shellService
            .setupClient(dto)
            .catch((err) => common_1.Logger.error(`Failed to setup client after add: ${err.message}`, err.stack, NodeService_1.name));
    }
};
NodeService = NodeService_1 = __decorate([
    common_1.Injectable(),
    __metadata("design:paramtypes", [shell_service_1.ShellService,
        config_service_1.ConfigService])
], NodeService);
exports.NodeService = NodeService;
//# sourceMappingURL=node.service.js.map