import { t as debug_default } from "./debug-DrrWgeSu.js";
import { t as configProvider } from "./config_provider-t1UIlTp8.js";
import { n as InvalidArgumentsException } from "./exceptions-I3WraG06.js";
//#region modules/encryption/define_config.ts
/**
* Defines the encryption configuration for the application.
*
* This function creates a configuration provider that lazily resolves
* encryption drivers. It validates that the default encryptor (if specified)
* exists in the list and resolves any ConfigProvider instances to their
* concrete values.
*
* @template KnownEncryptors - Record of encryptor names to their configurations
*
* @param config - The encryption configuration object
* @param config.default - Optional default encryptor name
* @param config.list - Map of encryptor names to their configurations or providers
*
* @example
* ```ts
* const encryptionConfig = defineConfig({
*   default: 'app',
*   list: {
*     app: drivers.aes256gcm({
*       id: 'app',
*       keys: [env.get('APP_KEY')]
*     }),
*     backup: drivers.chacha20({
*       id: 'backup',
*       keys: [env.get('BACKUP_KEY')]
*     })
*   }
* })
* ```
*/
function defineConfig(config) {
	/**
	* Encryption list should always be provided
	*/
	if (!config.list) throw new InvalidArgumentsException("Missing \"list\" property in encryption config");
	/**
	* The default encryption should be mentioned in the list
	*/
	if (config.default && !config.list[config.default]) throw new InvalidArgumentsException(`Missing "list.${String(config.default)}" in encryption config. It is referenced by the "default" property`);
	/**
	* Config provider to lazily import drivers as they are used inside
	* the user application
	*/
	return configProvider.create(async (app) => {
		debug_default("resolving encryption config");
		const encryptorsList = Object.keys(config.list);
		const encryptors = {};
		for (let encryptorName of encryptorsList) {
			const encryptor = config.list[encryptorName];
			if ("resolver" in encryptor) encryptors[encryptorName] = await encryptor.resolver(app);
			else encryptors[encryptorName] = encryptor;
		}
		return {
			default: config.default,
			list: encryptors
		};
	});
}
/**
* Collection of encryption driver factory functions.
*
* Each driver factory creates a ConfigProvider that lazily imports
* and configures the corresponding encryption driver. This allows
* for efficient code splitting and on-demand loading of encryption
* algorithms.
*/
const drivers = {
	chacha20: (config) => {
		return configProvider.create(async () => {
			const { ChaCha20Poly1305 } = await import("./modules/encryption/drivers/chacha20_poly1305.js");
			debug_default("configuring chacha20 encryption driver");
			return {
				driver: (key) => new ChaCha20Poly1305({
					id: config.id,
					key
				}),
				keys: config.keys.filter((key) => !!key)
			};
		});
	},
	aes256cbc: (config) => {
		return configProvider.create(async () => {
			const { AES256CBC } = await import("./modules/encryption/drivers/aes_256_cbc.js");
			debug_default("configuring aes256cbc encryption driver");
			return {
				driver: (key) => new AES256CBC({
					id: config.id,
					key
				}),
				keys: config.keys.filter((key) => !!key)
			};
		});
	},
	aes256gcm: (config) => {
		return configProvider.create(async () => {
			const { AES256GCM } = await import("./modules/encryption/drivers/aes_256_gcm.js");
			debug_default("configuring aes256gcm encryption driver");
			return {
				driver: (key) => new AES256GCM({
					id: config.id,
					key
				}),
				keys: config.keys.filter((key) => !!key)
			};
		});
	},
	aessiv: (config) => {
		return configProvider.create(async () => {
			const { AESSIV } = await import("./modules/encryption/drivers/aes_siv.js");
			debug_default("configuring aessiv encryption driver");
			return {
				driver: (key) => new AESSIV({
					id: config.id,
					key
				}),
				keys: [config.key].filter((key) => !!key)
			};
		});
	},
	legacy: (config) => {
		return configProvider.create(async () => {
			const { Legacy } = await import("./modules/encryption/drivers/legacy.js");
			debug_default("configuring legacy encryption driver");
			return {
				driver: (key) => new Legacy({ key }),
				keys: config.keys.filter((key) => !!key)
			};
		});
	}
};
//#endregion
export { drivers as n, defineConfig as t };
