"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getProviderTree = getProviderTree;
function __assignType(fn, args) {
    fn.__type = args;
    return fn;
}
const core_1 = require("@deepkit/core");
const injector_1 = require("@deepkit/injector");
const lodash_1 = require("lodash");
function getProviderTree(module) {
    const result = (0, lodash_1.compact)(module.providers.map(__assignType(p => {
        if ((0, core_1.isClass)(p)) {
            const name = getProviderName(p);
            if (name) {
                return {
                    name,
                    module,
                    provide: p
                };
            }
        }
        else if ((0, injector_1.isValueProvider)(p) || (0, injector_1.isClassProvider)(p) || (0, injector_1.isExistingProvider)(p) || (0, injector_1.isFactoryProvider)(p)) {
            if (p.scope)
                return null;
            const name = getProviderName(p.provide);
            if (name) {
                return {
                    name,
                    module,
                    provide: p.provide
                };
            }
        }
        return null;
    }, ['p', '', 'P"2!"/"'])));
    for (const anImport of module.imports) {
        result.push(...getProviderTree(anImport));
    }
    return result;
}
getProviderTree.__type = [() => injector_1.InjectorModule, 'module', 'getProviderTree', 'PP7!2""/#'];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function getProviderName(p) {
    if (typeof p === 'string') {
        return p;
    }
    const className = (0, core_1.getClassName)(p);
    return className !== 'undefined' && className !== 'anonymous class' ? className : null;
}
getProviderName.__type = ['p', 'getProviderName', 'P"2!"/"'];
//# sourceMappingURL=injection.js.map