(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "./TypeKey"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var TypeKey_1 = require("./TypeKey");
    var InjectedTypes = /** @class */ (function () {
        function InjectedTypes() {
        }
        InjectedTypes.getParamList = function (key, typeKey1) {
            var plist = InjectedTypes.paramList[typeKey1];
            // We need to find @Inject for base types if
            // current type does not define any constructor
            var type = key;
            while (plist === undefined) {
                type = Object.getPrototypeOf(type);
                if (!type) {
                    break;
                }
                var typeKey = TypeKey_1.TypeKey.get(type);
                plist = InjectedTypes.paramList[typeKey];
                if (!plist) {
                    InjectedTypes.paramList[typeKey] = plist;
                }
            }
            return plist;
        };
        InjectedTypes.getPropertyList = function (key, typeKey1) {
            var plist = InjectedTypes.propertyList[typeKey1];
            // We need to find @Inject for base types if
            // current type does not define any constructor
            var type = key;
            while (plist === undefined) {
                type = Object.getPrototypeOf(type);
                if (!type) {
                    break;
                }
                var typeKey = TypeKey_1.TypeKey.get(type);
                plist = InjectedTypes.propertyList[typeKey];
                if (!plist) {
                    InjectedTypes.propertyList[typeKey] = plist;
                }
            }
            return plist;
        };
        InjectedTypes.paramList = {};
        InjectedTypes.propertyList = {};
        return InjectedTypes;
    }());
    exports.InjectedTypes = InjectedTypes;
    // export function Inject(target: any, name: string): void;
    function Inject(target, name, index) {
        if (index !== undefined) {
            var key = TypeKey_1.TypeKey.get(target);
            var plist = Reflect.getMetadata("design:paramtypes", target, name);
            if (typeof index === "number") {
                var pSavedList = InjectedTypes.paramList[key] || (InjectedTypes.paramList[key] = []);
                pSavedList[index] = plist[index];
            }
            else {
                throw new Error("Inject can only be applied on constructor" +
                    "parameter or a property without get/set methods");
            }
        }
        else {
            var key = TypeKey_1.TypeKey.get(target.constructor);
            var plist = Reflect.getMetadata("design:type", target, name);
            var p = InjectedTypes.propertyList[key] || (InjectedTypes.propertyList[key] = {});
            p[name] = plist;
            // need to merge base properties..
            var base = target.constructor;
            while (true) {
                base = Object.getPrototypeOf(base);
                if (!base) {
                    break;
                }
                var baseKey = TypeKey_1.TypeKey.get(base);
                var bp = InjectedTypes.propertyList[baseKey];
                if (bp) {
                    for (var pKey in bp) {
                        if (bp.hasOwnProperty(pKey)) {
                            var element = bp[pKey];
                            if (!p[pKey]) {
                                p[pKey] = element;
                            }
                        }
                    }
                }
            }
        }
    }
    exports.Inject = Inject;
});
//# sourceMappingURL=Inject.js.map