import { validateAdapterCapabilities } from "./adapter-compat.js";
const CHANNEL_ADAPTER_REGISTRY_KEY = /* @__PURE__ */ Symbol.for("@open-mercato/communication-channels/adapter-registry");
function getRegistryMap() {
  const scope = globalThis;
  if (!scope[CHANNEL_ADAPTER_REGISTRY_KEY]) {
    scope[CHANNEL_ADAPTER_REGISTRY_KEY] = /* @__PURE__ */ new Map();
  }
  return scope[CHANNEL_ADAPTER_REGISTRY_KEY];
}
function registerChannelAdapter(adapter) {
  validateAdapterCapabilities(adapter);
  const map = getRegistryMap();
  if (map.has(adapter.providerKey)) {
    throw new Error(
      `ChannelAdapter '${adapter.providerKey}' is already registered. Each provider package must declare a unique providerKey.`
    );
  }
  map.set(adapter.providerKey, adapter);
  return () => {
    map.delete(adapter.providerKey);
  };
}
function getChannelAdapter(providerKey) {
  return getRegistryMap().get(providerKey);
}
function listChannelAdapters() {
  return Array.from(getRegistryMap().values());
}
function listChannelAdapterProviderKeys() {
  return Array.from(getRegistryMap().keys());
}
function hasChannelAdapter(providerKey) {
  return getRegistryMap().has(providerKey);
}
function clearChannelAdapters() {
  getRegistryMap().clear();
}
class ChannelAdapterRegistry {
  register(adapter) {
    registerChannelAdapter(adapter);
  }
  get(providerKey) {
    return getChannelAdapter(providerKey);
  }
  list() {
    return listChannelAdapters();
  }
  providerKeys() {
    return listChannelAdapterProviderKeys();
  }
  has(providerKey) {
    return hasChannelAdapter(providerKey);
  }
  clear() {
    clearChannelAdapters();
  }
}
export {
  ChannelAdapterRegistry,
  clearChannelAdapters,
  getChannelAdapter,
  hasChannelAdapter,
  listChannelAdapterProviderKeys,
  listChannelAdapters,
  registerChannelAdapter
};
//# sourceMappingURL=registry.js.map
