// Force strict mode and setup for ESM
"use strict";
import {
  init_esbuild_shims
} from "./chunk-5O2XNYP6.js";
import {
  __name
} from "./chunk-J2S4EL5Y.js";

// packages/cli/src/commands/channel/channel-registry.ts
init_esbuild_shims();
var registry = /* @__PURE__ */ new Map();
var builtinsPromise = null;
function ensureBuiltins() {
  if (!builtinsPromise) {
    builtinsPromise = (async () => {
      const labelled = [
        { name: "telegram", promise: import("./dist-3BMEUGTG.js") },
        { name: "weixin", promise: import("./dist-7JGAAQSC.js") },
        { name: "dingtalk", promise: import("./dist-A7H2KKUC.js") },
        { name: "wecom", promise: import("./dist-HVBMEYWK.js") },
        { name: "feishu", promise: import("./dist-DPPHJAVL.js") },
        { name: "qqbot", promise: import("./dist-SFQ34F4M.js") },
        { name: "github", promise: import("./dist-4KAX7CCL.js") },
        { name: "gitlab", promise: import("./dist-NEBRI7WO.js") }
      ];
      const results = await Promise.allSettled(labelled.map((l) => l.promise));
      for (let i = 0; i < results.length; i++) {
        const result = results[i];
        if (result.status === "fulfilled") {
          registry.set(result.value.plugin.channelType, result.value.plugin);
        } else {
          process.stderr.write(
            `[channel-registry] Failed to load "${labelled[i].name}" channel: ${result.reason}
`
          );
        }
      }
    })();
  }
  return builtinsPromise;
}
__name(ensureBuiltins, "ensureBuiltins");
function registerPlugin(plugin) {
  if (registry.has(plugin.channelType)) {
    throw new Error(
      `Channel type "${plugin.channelType}" is already registered.`
    );
  }
  registry.set(plugin.channelType, plugin);
}
__name(registerPlugin, "registerPlugin");
async function getPlugin(channelType) {
  await ensureBuiltins();
  return registry.get(channelType);
}
__name(getPlugin, "getPlugin");
async function supportedTypes() {
  await ensureBuiltins();
  return [...registry.keys()];
}
__name(supportedTypes, "supportedTypes");
async function supportedChannelCatalog() {
  await ensureBuiltins();
  return [...registry.values()].map(
    ({ channelType, displayName, management }) => ({
      type: channelType,
      displayName,
      manageable: management !== void 0,
      fields: management?.fields ?? []
    })
  );
}
__name(supportedChannelCatalog, "supportedChannelCatalog");

export {
  registerPlugin,
  getPlugin,
  supportedTypes,
  supportedChannelCatalog
};
