"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
;
var InterceptorChain = /** @class */ (function () {
    function InterceptorChain(target) {
        this.target = target;
        this.interceptors = [];
    }
    InterceptorChain.prototype.addInterceptor = function (interceptor) {
        this.interceptors.push(typeof interceptor == "function" ? {
            intercept: interceptor
        } : interceptor);
        return this;
    };
    InterceptorChain.prototype.execute = function (context) {
        var _this = this;
        var runner = {
            index: 0,
            run: function (context) {
                if (runner.index < _this.interceptors.length) {
                    runner.index++;
                    return _this.interceptors[runner.index - 1].intercept(context, {
                        handle: function (context) {
                            return runner.run(context);
                        }
                    });
                }
                else {
                    return _this.target(context);
                }
            }
        };
        return runner.run(context);
    };
    return InterceptorChain;
}());
exports.InterceptorChain = InterceptorChain;
