

const require_KeyManagementError = require('../error/KeyManagementError.js');
const require_humanDescription = require('../jwk/humanDescription.js');
require('../jwk/index.js');

//#region src/modules/kms/options/KmsOperation.ts
function getKmsOperationHumanDescription(operation) {
	if (operation.operation === "deleteKey") return "'deleteKey' operation";
	if (operation.operation === "createKey") {
		let base = `'createKey' operation with kty '${operation.type.kty}'`;
		if (operation.type.kty === "EC" || operation.type.kty === "OKP") base += ` and crv '${operation.type.crv}'`;
		else if (operation.type.kty === "RSA") base += ` and bit length '${operation.type.modulusLength}'`;
		else if (operation.type.kty === "oct") {
			base += ` and algorithm '${operation.type.algorithm}'`;
			if (operation.type.algorithm === "aes" || operation.type.algorithm === "hmac") base += ` with key length '${operation.type.length}'`;
		}
		return base;
	}
	if (operation.operation === "importKey") return `'importKey' operation with ${require_humanDescription.getJwkHumanDescription(operation.privateJwk)}`;
	if (operation.operation === "sign" || operation.operation === "verify") return `'${operation.operation}' operation with algorithm '${operation.algorithm}'`;
	if (operation.operation === "encrypt") {
		let message = `'encrypt' operation with encryption algorithm '${operation.encryption.algorithm}'`;
		if (operation.keyAgreement) message += `and key agreement algorithm '${operation.keyAgreement.algorithm}'`;
		return message;
	}
	if (operation.operation === "decrypt") {
		let message = `'decrypt' operation with encryption algorithm '${operation.decryption.algorithm}'`;
		if (operation.keyAgreement) message += `and key agreement algorithm '${operation.keyAgreement.algorithm}'`;
		return message;
	}
	if (operation.operation === "randomBytes") return `'randomBytes' operation`;
	throw new require_KeyManagementError.KeyManagementError("Unsupported operation");
}

//#endregion
exports.getKmsOperationHumanDescription = getKmsOperationHumanDescription;