var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
var __spread = (this && this.__spread) || function () {
    for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
    return ar;
};
import { AbstractService } from './abstract-service';
/**
 * This class will be augmented when importing specific service
 * For example:
 * ```typescript
 * const container: ServiceContainer;
 * expect(container.interface).to.be.undefined;
 * import '@iotize/tap/service/interface';
 * expect(container.interface).to.be.not.undefined;
 *
 * ```
 */
var ServiceContainer = /** @class */ (function () {
    function ServiceContainer(serviceCallRunner) {
        this.serviceCallRunner = serviceCallRunner;
    }
    /**
     * List loaded services
     */
    ServiceContainer.prototype.services = function () {
        return Object.values(this.servicesMap());
    };
    ServiceContainer.prototype.servicesMap = function () {
        var services = {};
        for (var key in this) {
            var hasDescriptor = Object.getOwnPropertyDescriptor(ServiceContainer.prototype, key);
            var value = this[key];
            if (hasDescriptor === null || hasDescriptor === void 0 ? void 0 : hasDescriptor.enumerable) {
                if (value instanceof AbstractService) {
                    services[key] = value;
                }
            }
        }
        return services;
    };
    /**
     * List all loaded resources
     */
    ServiceContainer.prototype.resources = function () {
        return this
            .services()
            .reduce(function (prev, service) {
            prev.push.apply(prev, __spread(Object.values(service.resources)));
            return prev;
        }, []);
    };
    return ServiceContainer;
}());
export { ServiceContainer };
export function extendServiceContainer(attrName, serviceConstructor) {
    var hiddenAttrName = "__" + attrName + "__";
    Object.defineProperty(ServiceContainer.prototype, hiddenAttrName, {
        enumerable: false,
        configurable: true,
        writable: true,
        value: undefined
    });
    return Object.defineProperty(ServiceContainer.prototype, attrName, {
        get: function () {
            var that = this;
            if (!that[hiddenAttrName]) {
                that[hiddenAttrName] = new serviceConstructor(this.serviceCallRunner);
            }
            return that[hiddenAttrName];
        },
        enumerable: true,
        configurable: true
    });
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VydmljZS1jb250YWluZXIuanMiLCJzb3VyY2VSb290Ijoibmc6Ly9AaW90aXplL3RhcC8iLCJzb3VyY2VzIjpbImxpYi9zZXJ2aWNlLWNvbnRhaW5lci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7OztBQUFBLE9BQU8sRUFBRSxlQUFlLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUlyRDs7Ozs7Ozs7OztHQVVHO0FBQ0g7SUFFSSwwQkFBNEIsaUJBQW9DO1FBQXBDLHNCQUFpQixHQUFqQixpQkFBaUIsQ0FBbUI7SUFFaEUsQ0FBQztJQUVEOztPQUVHO0lBQ0gsbUNBQVEsR0FBUjtRQUNJLE9BQU8sTUFBTSxDQUFDLE1BQU0sQ0FBQyxJQUFJLENBQUMsV0FBVyxFQUFFLENBQUMsQ0FBQztJQUM3QyxDQUFDO0lBRUQsc0NBQVcsR0FBWDtRQUNJLElBQU0sUUFBUSxHQUFvQyxFQUFFLENBQUM7UUFDckQsS0FBSyxJQUFNLEdBQUcsSUFBSSxJQUFJLEVBQUU7WUFDcEIsSUFBTSxhQUFhLEdBQUcsTUFBTSxDQUFDLHdCQUF3QixDQUFDLGdCQUFnQixDQUFDLFNBQVMsRUFBRSxHQUFHLENBQUMsQ0FBQztZQUN2RixJQUFNLEtBQUssR0FBRyxJQUFJLENBQUMsR0FBRyxDQUFDLENBQUM7WUFDeEIsSUFBSSxhQUFhLGFBQWIsYUFBYSx1QkFBYixhQUFhLENBQUUsVUFBVSxFQUFFO2dCQUMzQixJQUFJLEtBQUssWUFBWSxlQUFlLEVBQUU7b0JBQ2xDLFFBQVEsQ0FBQyxHQUFHLENBQUMsR0FBRyxLQUFLLENBQ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