import defaultTypes from "../message-objects.js";
import { createLogger } from "@open-mercato/shared/lib/logger";
const logger = createLogger("messages");
const registry = /* @__PURE__ */ new Map();
function getKey(module, entityType) {
  return `${module}:${entityType}`;
}
function ensureDefaults() {
  if (registry.size > 0) return;
  registerMessageObjectTypes(defaultTypes);
}
function registerMessageObjectTypes(types, options = {}) {
  if (options.replace) {
    registry.clear();
  }
  for (const type of types) {
    const key = getKey(type.module, type.entityType);
    if (registry.has(key)) {
      logger.warn("Message object type already registered, overwriting", { key });
    }
    registry.set(key, type);
  }
}
function getMessageObjectType(module, entityType) {
  ensureDefaults();
  return registry.get(getKey(module, entityType));
}
function isMessageObjectTypeAllowedForMessageType(objectType, messageType) {
  if (!messageType || !messageType.trim()) return true;
  const allowed = objectType.messageTypes;
  if (!Array.isArray(allowed) || allowed.length === 0) return true;
  return allowed.includes(messageType);
}
function getMessageObjectTypesForMessageType(messageType) {
  ensureDefaults();
  return Array.from(registry.values()).filter(
    (objectType) => isMessageObjectTypeAllowedForMessageType(objectType, messageType)
  );
}
function getAllMessageObjectTypes() {
  ensureDefaults();
  return Array.from(registry.values());
}
export {
  getAllMessageObjectTypes,
  getMessageObjectType,
  getMessageObjectTypesForMessageType,
  isMessageObjectTypeAllowedForMessageType,
  registerMessageObjectTypes
};
//# sourceMappingURL=message-objects-registry.js.map
