import { createLogger } from "../utils/logger/index.js";
import { init_logger } from "../utils/logger.js";
//#region src/media-understanding/registry.ts
init_logger();
const log = createLogger("MediaUnderstandingRegistry");
const registry = /* @__PURE__ */ new Map();
function normalizeId(id) {
	return id.trim().toLowerCase();
}
function indexProvider(provider) {
	const keys = [normalizeId(provider.id)];
	for (const alias of provider.aliases ?? []) keys.push(normalizeId(alias));
	return keys;
}
function registerMediaUnderstandingProvider(provider) {
	const keys = indexProvider(provider);
	const conflicts = keys.filter((key) => registry.has(key));
	if (conflicts.length > 0) log.warn({
		providerId: provider.id,
		conflicts
	}, `Media-understanding provider "${provider.id}" overrides existing registration(s): ${conflicts.join(", ")}`);
	for (const key of keys) registry.set(key, provider);
	return () => {
		for (const key of keys) if (registry.get(key) === provider) registry.delete(key);
	};
}
function getMediaUnderstandingProvider(id) {
	return registry.get(normalizeId(id));
}
function listMediaUnderstandingProviders() {
	const seen = /* @__PURE__ */ new Set();
	const result = [];
	for (const provider of registry.values()) if (!seen.has(provider)) {
		seen.add(provider);
		result.push(provider);
	}
	return result;
}
/**
* List providers that DECLARE the requested capability via `capabilities[]`
* AND have an actual method implementation. The runner uses this to build
* the per-capability fallback chain.
*/
function listProvidersForCapability(capability) {
	const methodKey = capability === "audio" ? "transcribeAudio" : capability === "image" ? "describeImage" : "describeVideo";
	return listMediaUnderstandingProviders().filter((provider) => {
		const declared = provider.capabilities?.includes(capability) ?? false;
		const implemented = typeof provider[methodKey] === "function";
		return declared && implemented;
	});
}
/** Test-only: clear the registry. Not exported from the package barrel. */
function _clearMediaUnderstandingRegistryForTests() {
	registry.clear();
}
//#endregion
export { _clearMediaUnderstandingRegistryForTests, getMediaUnderstandingProvider, listMediaUnderstandingProviders, listProvidersForCapability, registerMediaUnderstandingProvider };

//# sourceMappingURL=registry.js.map