import { CredentialStoreType } from "../types/utility.js";

//#region src/utils/credential-store-utils.ts
/**
* Get a lookup key for a credential store from retrieval params
* @param retrievalParams - The retrieval params for the credential store
* @param credentialStoreType - The type of credential store
* @returns A lookup key for the credential store, used to call <CredentialStore>.get()
*/
function getCredentialStoreLookupKeyFromRetrievalParams({ retrievalParams, credentialStoreType }) {
	if (retrievalParams.key) return retrievalParams.key;
	if (credentialStoreType === CredentialStoreType.nango) return JSON.stringify({
		connectionId: retrievalParams.connectionId,
		providerConfigKey: retrievalParams.providerConfigKey
	});
	if (credentialStoreType === CredentialStoreType.composio) return retrievalParams.connectedAccountId ?? null;
	return null;
}

//#endregion
export { getCredentialStoreLookupKeyFromRetrievalParams };