'use strict';
import { getSourceFiles, initInternalResourceMetaHandlers, isDecoratedWithResourceId, initInternalResourceMeta } from '../../meta/server/resources/resource-meta-plugin.js';
import { getInternalResourceMeta, setInternalResourceMeta } from '../../meta/server/resources/internal-resource-meta.js';
import { dynamicImportResource, dynamicImportResourceExt, formatRelativePathForImport } from '../../meta/server/modules/dynamic-imports.js';
import { getBooleanEnvSetting } from '../../../fd-toolbox/infra/env-functions.js';
import { resourceFolders } from '../../../fd-toolbox/constants/resource-folders.js';
import { isPackageNodeMode } from '../../../fd-toolbox/lib/environments.js';
import { isExtendedResource } from '../../meta/server/resources/resource-checker.js';
import { toolboxEnvSettingKeys } from '../../../fd-toolbox/infra/toolbox-env-setting-keys.js';
import { fileExtensions } from '../../../base-repo/app-constants/internal-system-constants.js';

var __defProp=Object['defineProperty'],__name=(_0x4e7017,_0x21b9a2)=>__defProp(_0x4e7017,'name',{'value':_0x21b9a2,'configurable':!![]});const handlersFileEnding='.handlers';async function initialize(){const _0x25a159=new Set(),_0x54197d=[],_0x2e1e82=[];for(const _0x331c36 of getSourceFiles()){const _0x59c138=_0x331c36['getFilePath'](),_0x143284=_0x59c138['endsWith'](handlersFileEnding+fileExtensions['ts'])||_0x59c138['endsWith'](handlersFileEnding+fileExtensions['js']);_0x143284?processHandlerFile(_0x331c36,_0x25a159):await processResourceFile(_0x331c36,_0x25a159,_0x54197d,_0x2e1e82);}for(const _0x271a94 of _0x54197d){await dynamicImportResource(_0x271a94);}for(const [_0x4b71dd,_0x248623]of _0x2e1e82){await dynamicImportResourceExt(_0x248623);const _0x1c8efe=await getInternalResourceMeta(_0x4b71dd),_0x508b3a=await getInternalResourceMeta(_0x1c8efe['extendedFrom']);_0x508b3a['properties']={..._0x508b3a['properties'],..._0x1c8efe['properties']},await setInternalResourceMeta(_0x508b3a);}return Array['from'](_0x25a159);}__name(initialize,'initialize');function checkResourcePackageFolder(_0x593ebe){if(!_0x593ebe)return ![];const _0x258c3b=[{'folder':resourceFolders['dev'],'envKey':toolboxEnvSettingKeys['seedDevResources']},{'folder':resourceFolders['demo'],'envKey':toolboxEnvSettingKeys['seedDemoResources']}];for(const _0x20c8a8 of _0x258c3b){if(_0x593ebe['includes']('/'+_0x20c8a8['folder']+'/')&&!getBooleanEnvSetting(_0x20c8a8['envKey'])&&!isPackageNodeMode())return ![];}return !![];}__name(checkResourcePackageFolder,'checkResourcePackageFolder');async function processHandlerFile(_0x364231,_0x2877d2){const _0x1a6865=await initInternalResourceMetaHandlers(_0x364231);_0x1a6865&&checkResourcePackageFolder(_0x364231['getFilePath']())&&_0x2877d2['add'](_0x1a6865);}__name(processHandlerFile,'processHandlerFile');async function processResourceFile(_0x33faf0,_0x44fd0,_0x2e3d58,_0xba17e){const _0x3571f4=formatRelativePathForImport(_0x33faf0['getFilePath']());for(const _0x2c5cd9 of _0x33faf0['getClasses']()){if(isDecoratedWithResourceId(_0x2c5cd9))_0x2e3d58['push'](_0x3571f4),await initInternalResourceMeta(_0x2c5cd9),checkResourcePackageFolder(_0x33faf0['getFilePath']())&&_0x44fd0['add'](_0x2c5cd9['getName']());else isExtendedResource(_0x2c5cd9)&&(_0xba17e['push']([_0x2c5cd9['getName'](),_0x3571f4]),await initInternalResourceMeta(_0x2c5cd9,!![]),checkResourcePackageFolder(_0x33faf0['getFilePath']())&&_0x44fd0['add'](_0x2c5cd9['getName']()));}}__name(processResourceFile,'processResourceFile');

export { initialize };
