"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const log_1 = require("@f2/log");
const ssh_client_1 = require("./@f2/ssh-client/ssh-client");
const unsolicited_auto_client_1 = require("./unsolicited-auto-client");
function main() {
    return __awaiter(this, void 0, void 0, function* () {
        const rootLogger = yield (0, log_1.buildLogger)({
            console: true,
            rotate: 'size',
            maxsize: 10 * 1024 * 1024,
            maxfiles: 6 * 30 // 6 mois
        });
        const appLogger = rootLogger.getLogger('App');
        const sshClient = new ssh_client_1.SshClient('192.168.3.10', {
            user: 'root',
            password: 'deltatau'
        });
        const bufLoggers = {};
        const buffers = [0, 1, 2, 3, 4, 5, 6, 7];
        buffers.forEach((buf) => {
            bufLoggers[buf] = rootLogger.getLogger(`b${buf}`);
        });
        const client = new unsolicited_auto_client_1.PmacUnsolicitedAutoClient(sshClient, buffers);
        client.start();
        client.on('message', (msg, buffer) => {
            bufLoggers[buffer].info(msg);
        });
        client.on('connect', () => {
            appLogger.info('Client connecté');
        });
        client.on('disconnect', () => {
            appLogger.info('Client déconnecté');
        });
        client.on('error', (err) => {
            appLogger.error(err);
        });
    });
}
main().catch(console.error);
