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

//#region src/credential-stores/memory-store.ts
/**
* In-memory credential store implementation
* Automatically loads environment variables prefixed with CREDENTIAL_STORE_ on initialization
* Note: Runtime credentials are lost when the server restarts, but env vars are reloaded
*/
var InMemoryCredentialStore = class {
	id;
	type = CredentialStoreType.memory;
	credentials = /* @__PURE__ */ new Map();
	constructor(id = "memory-default") {
		this.id = id;
	}
	/**
	* Get a credential from the in memory store.
	* If the key is not found in the in memory store then it is loaded from environment variables.
	* If the key is not found in the environment variables or in the in memory store then returns null.
	* @param key - The key of the credential to get
	* @returns The credential value or null if not found
	*/
	async get(key) {
		const credential = this.credentials.get(key);
		if (!credential) {
			const envValue = process.env[key];
			if (envValue) {
				this.credentials.set(key, envValue);
				return envValue;
			}
			return null;
		}
		return credential;
	}
	/**
	* Set a credential in the in memory store.
	* @param key - The key of the credential to set
	* @param value - The value of the credential to set
	* @param metadata - Optional metadata (ignored by memory store)
	*/
	async set(key, value, _metadata) {
		this.credentials.set(key, value);
	}
	/**
	* Check if a credential exists in the in memory store.
	* @param key - The key of the credential to check
	* @returns True if the credential exists, false otherwise
	*/
	async has(key) {
		return this.credentials.has(key);
	}
	/**
	* Delete a credential from the in memory store.
	* @param key - The key of the credential to delete
	* @returns True if the credential was deleted, false otherwise
	*/
	async delete(key) {
		return this.credentials.delete(key);
	}
	/**
	* Check if the credential store is available and functional
	*/
	async checkAvailability() {
		return { available: true };
	}
};

//#endregion
export { InMemoryCredentialStore };