

const require_KeyManagementError = require('./error/KeyManagementError.js');
const require_classPrivateFieldInitSpec = require('../../_virtual/_@oxc-project_runtime@0.94.0/helpers/classPrivateFieldInitSpec.js');
const require_classPrivateFieldSet2 = require('../../_virtual/_@oxc-project_runtime@0.94.0/helpers/classPrivateFieldSet2.js');
const require_classPrivateFieldGet2 = require('../../_virtual/_@oxc-project_runtime@0.94.0/helpers/classPrivateFieldGet2.js');

//#region src/modules/kms/KeyManagementModuleConfig.ts
var _defaultBackend = /* @__PURE__ */ new WeakMap();
var _backends = /* @__PURE__ */ new WeakMap();
var KeyManagementModuleConfig = class {
	constructor(options) {
		require_classPrivateFieldInitSpec._classPrivateFieldInitSpec(this, _defaultBackend, void 0);
		require_classPrivateFieldInitSpec._classPrivateFieldInitSpec(this, _backends, void 0);
		require_classPrivateFieldSet2._classPrivateFieldSet2(_backends, this, options.backends ?? []);
		if (options.defaultBackend) {
			if (!require_classPrivateFieldGet2._classPrivateFieldGet2(_backends, this).find((kms) => kms.backend === options.defaultBackend)) throw new require_KeyManagementError.KeyManagementError(`Default backend '${options.defaultBackend}' provided in KeyManagementModuleConfig, but not found in 'backends'. Make sure the backend identifier matches with a registered backend.`);
			require_classPrivateFieldSet2._classPrivateFieldSet2(_defaultBackend, this, options.defaultBackend);
		}
	}
	get backends() {
		return require_classPrivateFieldGet2._classPrivateFieldGet2(_backends, this);
	}
	registerBackend(backend) {
		this.backends.push(backend);
	}
	get defaultBackend() {
		const backend = this.backends.find((kms) => !require_classPrivateFieldGet2._classPrivateFieldGet2(_defaultBackend, this) || require_classPrivateFieldGet2._classPrivateFieldGet2(_defaultBackend, this) === kms.backend);
		if (!backend) throw new require_KeyManagementError.KeyManagementError("Unable to determine default backend. ");
		return backend;
	}
	toJSON() {
		return {
			defaultBackend: require_classPrivateFieldGet2._classPrivateFieldGet2(_defaultBackend, this),
			backends: this.backends.map((backend) => backend.backend)
		};
	}
};

//#endregion
exports.KeyManagementModuleConfig = KeyManagementModuleConfig;