"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.r = void 0;
exports.resolve = resolve;
exports.resolveDeep = resolveDeep;
exports.getOrCreateInjectorForModule = getOrCreateInjectorForModule;
exports.getApp = getApp;
exports.getAppModule = getAppModule;
exports.getAppConfig = getAppConfig;
/*@ts-ignore*/
var { __ΩClassType } = require('@deepkit/core');
const state_1 = require("./state");
const injector_1 = require("@deepkit/injector");
const resolveCache = new WeakMap();
function resolve(type) {
    const cached = resolveCache.get(type);
    if (cached)
        return cached;
    const app = state_1.globalState.currentApp;
    if (!app)
        throw new Error('No app initialized');
    const resolved = app.get(type);
    resolveCache.set(type, resolved);
    return resolved;
}
resolve.__type = [() => __ΩClassType, 'type', 'resolve', 'P"o!"2""/#'];
exports.r = resolve;
function resolveDeep(type, fromModule = getAppModule()) {
    if (fromModule.isProvided(type)) {
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
        return getOrCreateInjectorForModule(fromModule).get(type);
    }
    if (fromModule.imports?.length) {
        for (const anImport of fromModule.imports) {
            const result = resolveDeep(type, anImport);
            if (result)
                return result;
        }
    }
}
resolveDeep.__type = [() => __ΩClassType, 'type', () => injector_1.InjectorModule, 'fromModule', () => getAppModule(), 'resolveDeep', 'P"o!"2"P7#2$>%P"-J/&'];
function getOrCreateInjectorForModule(module) {
    return state_1.globalState.currentApp.getInjectorContext().getInjector(module);
}
getOrCreateInjectorForModule.__type = [() => injector_1.InjectorModule, 'module', () => injector_1.Injector, 'getOrCreateInjectorForModule', 'PP7!2"P7#/$'];
function getApp() {
    if (!state_1.globalState.currentApp)
        throw new Error('No app initialized');
    return state_1.globalState.currentApp;
}
getApp.__type = ['getApp', 'P"/!'];
function getAppModule() {
    return getApp().appModule;
}
getAppModule.__type = ['getAppModule', 'P"/!'];
function getAppConfig() {
    return getAppModule().config;
}
getAppConfig.__type = ['getAppConfig', 'P"/!'];
//# sourceMappingURL=resolver.js.map