"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.watchTreeAndLog = exports.watchGraphAndLog = exports.watchUnitAndLog = void 0;
const Unit_1 = require("../Class/Unit");
const GRAPH_DEFAULT_EVENTS_1 = require("../constant/GRAPH_DEFAULT_EVENTS");
const watchGraph_1 = require("./graph/watchGraph");
const watchTree_1 = require("./watchTree");
const watchUnit_1 = require("./watchUnit");
/* eslint-disable no-console */
const watchUnitAndLog = (unit, events = GRAPH_DEFAULT_EVENTS_1.GRAPH_DEFAULT_EVENTS) => (0, watchUnit_1.watchUnit)(unit, (moment) => {
    const { data } = moment;
    if (data.data instanceof Unit_1.Unit) {
        data.data = data.data.constructor.name;
    }
    console.log(moment);
}, events);
exports.watchUnitAndLog = watchUnitAndLog;
const watchGraphAndLog = (graph, events = GRAPH_DEFAULT_EVENTS_1.GRAPH_DEFAULT_EVENTS) => {
    return (0, watchGraph_1.watchGraph)(graph, (moment) => {
        const { type, event, data } = moment;
        if (data.data instanceof Unit_1.Unit) {
            data.data = data.data.constructor.name;
        }
        const { unitId, pinId, data: _data, err } = data;
        // console.log(moment)
        console.log(type, event, unitId, pinId, _data !== undefined ? JSON.stringify(_data) : '', err || '');
    }, events);
};
exports.watchGraphAndLog = watchGraphAndLog;
const watchTreeAndLog = (unit, events = GRAPH_DEFAULT_EVENTS_1.GRAPH_DEFAULT_EVENTS) => {
    return (0, watchTree_1.watchTree)(unit, events, (path, moment) => {
        const { type, event, data } = moment;
        const { pinId, err, data: _data } = data;
        const t = path.map(() => '- ').join('');
        console.log(`${t}${path[path.length - 1] || ''} ${type} ${pinId} ${event} ${_data !== undefined ? JSON.stringify(_data) : ''} ${err !== undefined ? JSON.stringify(err) : ''}`);
    });
};
exports.watchTreeAndLog = watchTreeAndLog;
//# sourceMappingURL=index.js.map