"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.proxyWrap = exports.proxy = void 0;
const ASYNC_GRAPH_PROXY_CALL_FILTER_1 = require("./constant/ASYNC_GRAPH_PROXY_CALL_FILTER");
const ASYNC_GRAPH_PROXY_WATCH_FILTER_1 = require("./constant/ASYNC_GRAPH_PROXY_WATCH_FILTER");
function proxy(unit, CALL, WATCH) {
    let stop_event = undefined;
    const proxy = new Proxy(unit, {
        get: (target, name) => {
            const value = target[name];
            // if (typeof value == 'function') {
            if (CALL[name]) {
                stop_event = CALL[name];
            }
            else if (WATCH.has(name)) {
                return (data, callback) => {
                    return value.call(target, data, (moment) => {
                        const { event } = moment;
                        if (stop_event === event) {
                            stop_event = undefined;
                        }
                        else {
                            callback(moment);
                        }
                    });
                };
            }
            // }
            return value;
        },
    });
    return proxy;
}
exports.proxy = proxy;
const ASYNC_INTERFACE_PROXY_CALL_FILTER = {
    $V: { $write: 'write' },
    $J: { $set: 'set' },
    $CA: { $draw: 'draw' },
    $G: ASYNC_GRAPH_PROXY_CALL_FILTER_1.ASYNC_GRAPH_PROXY_CALL_FILTER,
    // TODO
    $B: {},
    $IB: {},
    $CC: {},
    $C: {},
    $CS: {},
    $CO: {},
    $GP: {},
    $M: {},
    $E: {},
    $EE: {},
    $BD: {},
    $BS: {},
    $BSE: {},
    $BC: {},
    $NO: {},
    $A: {},
    $PP: {},
    $PS: {},
    $CH: {},
    $ST: {},
    $S: {},
    $U: {},
    $TR: {},
    $RE: {},
};
const ASYNC_INTERFACE_PROXY_WATCH_FILTER = {
    $G: ASYNC_GRAPH_PROXY_WATCH_FILTER_1.ASYNC_GRAPH_PROXY_WATCH_FILTER,
};
function proxyWrap(unit, _ = []) {
    let CALL = {};
    let WATCH = new Set();
    for (const __ of _) {
        const CALL_FILTER = ASYNC_INTERFACE_PROXY_CALL_FILTER[__] || {};
        const WATCH_FILTER = ASYNC_INTERFACE_PROXY_WATCH_FILTER[__] || new Set();
        CALL = Object.assign(Object.assign({}, CALL), CALL_FILTER);
        WATCH = new Set([...WATCH, ...WATCH_FILTER]);
    }
    return proxy(unit, CALL, WATCH);
}
exports.proxyWrap = proxyWrap;
//# sourceMappingURL=proxyWrap.js.map