

const require_KeyManagementModule = require('../modules/kms/KeyManagementModule.js');
require('../modules/kms/index.js');
const require_X509Module = require('../modules/x509/X509Module.js');
require('../modules/x509/index.js');
const require_SingleContextStorageLruCache = require('../modules/cache/singleContextLruCache/SingleContextStorageLruCache.js');
const require_CacheModule = require('../modules/cache/CacheModule.js');
require('../modules/cache/index.js');
const require_DidsModule = require('../modules/dids/DidsModule.js');
require('../modules/dids/index.js');
const require_W3cCredentialsModule = require('../modules/vc/W3cCredentialsModule.js');
require('../modules/vc/index.js');
const require_MdocModule = require('../modules/mdoc/MdocModule.js');
const require_SdJwtVcModule = require('../modules/sd-jwt-vc/SdJwtVcModule.js');
require('../modules/sd-jwt-vc/index.js');
const require_DcqlModule = require('../modules/dcql/DcqlModule.js');
const require_DifPresentationExchangeModule = require('../modules/dif-presentation-exchange/DifPresentationExchangeModule.js');
require('../modules/dif-presentation-exchange/index.js');
const require_GenericRecordsModule = require('../modules/generic-records/GenericRecordsModule.js');
require('../modules/generic-records/index.js');

//#region src/agent/AgentModules.ts
/**
* Method to get the default agent modules to be registered on any agent instance. It doens't configure the modules in any way,
* and if that's needed the user needs to provide the module in the agent constructor
*/
function getDefaultAgentModules() {
	return {
		dcql: () => new require_DcqlModule.DcqlModule(),
		genericRecords: () => new require_GenericRecordsModule.GenericRecordsModule(),
		dids: () => new require_DidsModule.DidsModule(),
		w3cCredentials: () => new require_W3cCredentialsModule.W3cCredentialsModule(),
		cache: () => new require_CacheModule.CacheModule({ cache: new require_SingleContextStorageLruCache.SingleContextStorageLruCache({ limit: 500 }) }),
		pex: () => new require_DifPresentationExchangeModule.DifPresentationExchangeModule(),
		sdJwtVc: () => new require_SdJwtVcModule.SdJwtVcModule(),
		x509: () => new require_X509Module.X509Module(),
		mdoc: () => new require_MdocModule.MdocModule(),
		kms: () => new require_KeyManagementModule.KeyManagementModule({})
	};
}
/**
* Extend the provided modules object with the default agent modules. If the modules property already contains a module with the same
* name as a default module, the module won't be added to the extended module object. This allows users of the framework to override
* the modules with custom configuration. The agent constructor type ensures you can't provide a different module for a key that registered
* on the default agent.
*/
function extendModulesWithDefaultModules(modules) {
	const defaultAgentModules = getDefaultAgentModules();
	const defaultAgentModuleKeys = Object.keys(defaultAgentModules);
	const defaultModules = [];
	const customModules = Object.entries(modules ?? {}).filter(([key]) => !defaultAgentModuleKeys.includes(key));
	for (const [moduleKey, getConfiguredModule] of Object.entries(defaultAgentModules)) defaultModules.push([moduleKey, modules?.[moduleKey] ?? getConfiguredModule()]);
	return Object.fromEntries([...defaultModules, ...customModules]);
}
/**
* Get the agent api object based on the modules registered in the dependency manager. For each registered module on the
* dependency manager, the method will extract the api class from the module, resolve it and assign it to the module key
* as provided in the agent constructor (or the {@link getDefaultAgentModules} method).
*
* Modules that don't have an api class defined ({@link Module.api} is undefined) will be ignored and won't be added to the
* api object.
*
* If the api of a module is passed in the `excluded` array, the api will not be added to the resulting api object.
*
* @example
* If the dependency manager has the following modules configured:
* ```ts
* {
*   connections: DidCommConnectionsModule
*   indy: IndyModule
* }
* ```
*
* And we call the `getAgentApi` method like this:
* ```ts
* const api = getAgentApi(dependencyManager)
* ```
*
* the resulting agent api will look like:
*
* ```ts
* {
*   connections: ConnectionsApi
* }
* ```
*
* The `indy` module has been ignored because it doesn't define an api class.
*/
function getAgentApi(dependencyManager, excludedApis = []) {
	return Object.entries(dependencyManager.registeredModules).reduce((api, [moduleKey, module$1]) => {
		if (!module$1.api) return api;
		const apiInstance = dependencyManager.resolve(module$1.api);
		if (excludedApis.includes(apiInstance)) return api;
		return {
			...api,
			[moduleKey]: apiInstance
		};
	}, {});
}

//#endregion
exports.extendModulesWithDefaultModules = extendModulesWithDefaultModules;
exports.getAgentApi = getAgentApi;