"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AsyncV = exports.AsyncVRef = exports.AsyncVWatch = exports.AsyncVCall = exports.AsyncVGet = void 0;
const _1 = require("../../../Class/$");
const stringify_1 = require("../../../spec/stringify");
const Async_1 = require("./Async");
const AsyncVGet = (value) => {
    return {
        $read({}, callback) {
            try {
                const data = value.read();
                const data_ = (0, stringify_1.stringify)(data);
                callback(data_);
            }
            catch (err) {
                callback(undefined, err.message);
            }
        },
    };
};
exports.AsyncVGet = AsyncVGet;
const AsyncVCall = (value) => {
    return {
        $write({ data }, callback) {
            try {
                value.write(data);
            }
            catch (err) {
                callback(undefined, err);
            }
        },
    };
};
exports.AsyncVCall = AsyncVCall;
const AsyncVWatch = (value) => {
    return {};
};
exports.AsyncVWatch = AsyncVWatch;
const AsyncVRef = (value) => {
    return {
        $refer({ __ }) {
            const obj = value.read();
            if (obj === undefined) {
                return null;
            }
            if (obj instanceof _1.$) {
                const $obj = (0, Async_1.Async)(obj, __, obj.__system.async);
                return $obj;
            }
            else {
                return null;
            }
        },
    };
};
exports.AsyncVRef = AsyncVRef;
const AsyncV = (value) => {
    return {
        ...(0, exports.AsyncVGet)(value),
        ...(0, exports.AsyncVCall)(value),
        ...(0, exports.AsyncVWatch)(value),
        ...(0, exports.AsyncVRef)(value),
    };
};
exports.AsyncV = AsyncV;
//# sourceMappingURL=AsyncV.js.map