"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ASYNC_WORKER = void 0;
exports.AsyncWorker = AsyncWorker;
exports.makeAsyncWorkerG = makeAsyncWorkerG;
exports.makeAsyncWorkerC = makeAsyncWorkerC;
exports.makeAsyncWorkerW = makeAsyncWorkerW;
exports.makeAsyncWorkerR = makeAsyncWorkerR;
const method_1 = require("./client/method");
const interface_1 = require("./interface");
const AsyncWrap_1 = require("./types/interface/async/AsyncWrap");
const object_1 = require("./util/object");
exports.ASYNC_WORKER = (0, object_1.mapObjKV)(interface_1.ALL_TYPES_MAP, (_) => (client) => {
    const { get, call, watch, ref } = method_1.METHOD[_];
    return {
        ...makeAsyncWorkerG(client, get),
        ...makeAsyncWorkerC(client, call),
        ...makeAsyncWorkerW(client, watch),
        ...makeAsyncWorkerR(client, ref),
    };
});
function AsyncWorker(client, _) {
    return (0, AsyncWrap_1.AsyncWrap)(client, _, exports.ASYNC_WORKER);
}
function makeAsyncWorkerG(client, METHOD_GET) {
    const _$_G = {};
    for (const name of METHOD_GET) {
        const $name = `$${name}`;
        _$_G[$name] = (data, callback) => {
            return client.get($name, data, callback);
        };
    }
    return _$_G;
}
function makeAsyncWorkerC(client, METHOD_CALL) {
    const _$_C = {};
    for (const name of METHOD_CALL) {
        const $name = `$${name}`;
        _$_C[$name] = (data, callback) => {
            return client.call($name, data, callback);
        };
    }
    return _$_C;
}
function makeAsyncWorkerW(client, METHOD_WATCH) {
    const _$_W = {};
    for (const name of METHOD_WATCH) {
        const $name = `$${name}`;
        _$_W[$name] = (data, callback) => {
            const unlisten = client.watch($name, data, callback);
            return unlisten;
        };
    }
    return _$_W;
}
function makeAsyncWorkerR(client, METHOD_REF) {
    const _$_R = {};
    for (const name of METHOD_REF) {
        const $name = `$${name}`;
        _$_R[$name] = (data) => {
            const { __ } = data;
            const ref_client = client.ref($name, data);
            const $ref = AsyncWorker(ref_client, __);
            return $ref;
        };
    }
    return _$_R;
}
//# sourceMappingURL=AsyncWorker.js.map