"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AsyncU = exports.AsyncURef = exports.AsyncUWatch = exports.AsyncUCall = exports.$$refGlobalObj = void 0;
const watchUnit_1 = require("../../../debug/watchUnit");
const global_1 = require("../../../global");
const proxyWrap_1 = require("../../../proxyWrap");
const evaluate_1 = require("../../../spec/evaluate");
const object_1 = require("../../../util/object");
const stringifyPinData_1 = require("../../stringifyPinData");
const Async_1 = require("./Async");
const $$refGlobalObj = (system, id, _) => {
    const $ = (0, global_1.getGlobalRef)(system, id);
    const $unit = (0, Async_1.Async)($, _);
    return $unit;
};
exports.$$refGlobalObj = $$refGlobalObj;
const AsyncUCall = (unit) => {
    return {
        $getGlobalId(data, callback) {
            const __global_id = unit.getGlobalId();
            callback(__global_id);
        },
        $play(data) {
            unit.play();
        },
        $pause(data) {
            unit.pause();
        },
        $reset(data) {
            unit.reset();
        },
        $push({ id, data }) {
            const classes = unit.__system.classes;
            const specs = unit.__system.specs;
            const _data = (0, evaluate_1.evaluate)(data, specs, classes);
            unit.push(id, _data);
        },
        $takeInput(data) {
            const { id } = data;
            unit.takeInput(id);
        },
        $setPinData({ type, pinId, data }) {
            const classes = unit.__system.classes;
            const specs = unit.__system.specs;
            const _data = (0, evaluate_1.evaluate)(data, specs, classes);
            unit.setPinData(type, pinId, _data);
        },
        $removePinData(data) {
            const { type, pinId } = data;
            unit.removePinData(type, pinId);
        },
        $getPinData(data, callback) {
            const _data = unit.getPinData();
            const __data = (0, stringifyPinData_1.stringifyPinData)(_data);
            callback(__data);
        },
        $getInputData(data, callback) {
            const _data = unit.getInputData();
            callback(_data);
        },
        $getRefInputData(data, callback) {
            const _data = unit.getRefInputData();
            const __data = (0, object_1.mapObjVK)(_data, (unit) => {
                const __ = unit.getInterface();
                const __global_id = unit.getGlobalId();
                return { __global_id, __ };
            });
            callback(__data);
        },
        $pullInput(data) {
            const { id } = data;
            const input = unit.getInput(id);
            input.pull();
        },
    };
};
exports.AsyncUCall = AsyncUCall;
const AsyncUWatch = (unit) => {
    return {
        $watch({ events }, callback) {
            return (0, watchUnit_1.watchUnit)(unit, callback, events);
        },
    };
};
exports.AsyncUWatch = AsyncUWatch;
const AsyncURef = (unit) => {
    return {
        $refGlobalObj(data) {
            const __system = unit.refSystem();
            const { __global_id, __ } = data;
            const $ = (0, exports.$$refGlobalObj)(__system, __global_id, __);
            return (0, proxyWrap_1.proxyWrap)($, __);
        },
    };
};
exports.AsyncURef = AsyncURef;
const AsyncU = (unit) => {
    return Object.assign(Object.assign(Object.assign({}, (0, exports.AsyncUCall)(unit)), (0, exports.AsyncUWatch)(unit)), (0, exports.AsyncURef)(unit));
};
exports.AsyncU = AsyncU;
//# sourceMappingURL=AsyncU.js.map