define(["require", "exports", "./flow_node_handler", "./service_task_extensions", ".."], function (require, exports, flow_node_handler_1, service_task_extensions_1, __1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    class ServiceTaskHandler extends flow_node_handler_1.FlowNodeHandler {
        constructor(container, invoker) {
            super();
            this.container = container;
            this.invoker = invoker;
        }
        async executeIntern(flowNode, processToken, context) {
            const tokenData = processToken.data || {};
            const serviceTaskExtensions = new service_task_extensions_1.ServiceTaskExtensions(flowNode.extensions);
            if (serviceTaskExtensions.isValid) {
                const serviceInstance = await this.container.resolveAsync(serviceTaskExtensions.module);
                let result;
                try {
                    const self = this;
                    const cb = function (data) {
                    };
                    const argumentsToPassThrough = (new Function('context', 'token', 'callback', 'return ' + serviceTaskExtensions.parameter)).call(tokenData, context, tokenData, cb) || [];
                    result = await this.invoker.invoke(serviceInstance, serviceTaskExtensions.method, serviceTaskExtensions.namspace, context, ...argumentsToPassThrough);
                }
                catch (err) {
                    result = err;
                }
                let finalResult = result;
                const toPojoOptions = { skipCalculation: true };
                if (result && typeof result.toPojos === 'function') {
                    finalResult = await result.toPojos(context, toPojoOptions);
                }
                else if (result && typeof result.toPojo === 'function') {
                    finalResult = await result.toPojo(context, toPojoOptions);
                }
                tokenData.current = finalResult;
                processToken.data = tokenData;
                return new __1.NextFlowNodeInfo(await this.getNextFlowNodeFor(flowNode, context), processToken);
            }
        }
    }
    exports.ServiceTaskHandler = ServiceTaskHandler;
});

//# sourceMappingURL=service_task_handler.js.map
