

import { KeyManagementError } from "./error/KeyManagementError.mjs";
import { _classPrivateFieldInitSpec } from "../../_virtual/_@oxc-project_runtime@0.95.0/helpers/classPrivateFieldInitSpec.mjs";
import { _classPrivateFieldSet2 } from "../../_virtual/_@oxc-project_runtime@0.95.0/helpers/classPrivateFieldSet2.mjs";
import { _classPrivateFieldGet2 } from "../../_virtual/_@oxc-project_runtime@0.95.0/helpers/classPrivateFieldGet2.mjs";

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

//#endregion
export { KeyManagementModuleConfig };
//# sourceMappingURL=KeyManagementModuleConfig.mjs.map