import { workflowDefinitionDataSchema } from "../data/validators.js";
import { createLogger } from "@open-mercato/shared/lib/logger";
const logger = createLogger("workflows");
const codeWorkflowRegistry = /* @__PURE__ */ new Map();
function registerCodeWorkflows(workflows) {
  for (const wf of workflows) {
    const validation = workflowDefinitionDataSchema.safeParse(wf.definition);
    if (!validation.success) {
      logger.warn("Code workflow failed validation", {
        workflowId: wf.workflowId,
        issues: validation.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ")
      });
      continue;
    }
    if (codeWorkflowRegistry.has(wf.workflowId)) {
      logger.warn("Duplicate code workflow ID \u2014 overwriting", { workflowId: wf.workflowId, moduleId: wf.moduleId });
    }
    codeWorkflowRegistry.set(wf.workflowId, wf);
  }
}
function getCodeWorkflow(workflowId) {
  return codeWorkflowRegistry.get(workflowId);
}
function getAllCodeWorkflows() {
  return Array.from(codeWorkflowRegistry.values());
}
function isCodeWorkflow(workflowId) {
  return codeWorkflowRegistry.has(workflowId);
}
function clearCodeWorkflowRegistry() {
  codeWorkflowRegistry.clear();
}
export {
  clearCodeWorkflowRegistry,
  getAllCodeWorkflows,
  getCodeWorkflow,
  isCodeWorkflow,
  registerCodeWorkflows
};
//# sourceMappingURL=code-registry.js.map
