import { CredentialStoreType } from "../types/utility.js";
import { getLogger } from "../utils/logger.js";
import { deleteComposioConnectedAccount, getComposioInstance } from "../utils/third-party-mcp-servers/composio-client.js";
import "../utils/third-party-mcp-servers/index.js";

//#region src/credential-stores/composio-store.ts
const logger = getLogger("composio-store");
/**
* Composio credential store.
*
* Composio handles OAuth/auth internally via MCP URL query params.
* The connected account ID is stored in the credential reference's
* retrievalParams and injected into the URL at runtime.
*
* The key passed to get/has/delete is the Composio connected_account_id.
*/
var ComposioCredentialStore = class {
	id;
	type = CredentialStoreType.composio;
	constructor(id) {
		this.id = id;
	}
	async get() {
		return null;
	}
	async set() {}
	async has(key) {
		const composio = getComposioInstance();
		if (!composio) return false;
		try {
			return (await composio.connectedAccounts.get(key))?.status === "ACTIVE";
		} catch (error) {
			logger.warn({
				error,
				connectedAccountId: key
			}, "Failed to check Composio connected account status - treating as unavailable");
			return false;
		}
	}
	async delete(key) {
		return deleteComposioConnectedAccount(key);
	}
	async checkAvailability() {
		if (!process.env.COMPOSIO_API_KEY) return {
			available: false,
			reason: "COMPOSIO_API_KEY not configured"
		};
		return { available: true };
	}
};

//#endregion
export { ComposioCredentialStore };