var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/solution/VenueBooking/utils/resource.ts
var resource_exports = {};
__export(resource_exports, {
  buildResourceProductMap: () => buildResourceProductMap,
  extractResourceIds: () => extractResourceIds
});
module.exports = __toCommonJS(resource_exports);
function extractResourceIds(products) {
  var _a;
  const ids = /* @__PURE__ */ new Set();
  for (const product of products) {
    const resources = (_a = product.product_resource) == null ? void 0 : _a.resources;
    if (!Array.isArray(resources))
      continue;
    for (const resource of resources) {
      if (resource.status !== 1)
        continue;
      const defaultRes = resource.default_resource || [];
      const optionalRes = resource.optional_resource || [];
      for (const id of [...defaultRes, ...optionalRes]) {
        if (typeof id === "number" && id > 0)
          ids.add(id);
      }
      const combined = resource.combined_resource;
      if (combined && combined.status === 1 && Array.isArray(combined.resource_ids)) {
        for (const id of combined.resource_ids) {
          if (typeof id === "number" && id > 0)
            ids.add(id);
        }
      }
    }
  }
  return Array.from(ids);
}
function buildResourceProductMap(products) {
  var _a;
  const map = /* @__PURE__ */ new Map();
  for (const product of products) {
    const resources = (_a = product.product_resource) == null ? void 0 : _a.resources;
    if (!Array.isArray(resources))
      continue;
    for (const resource of resources) {
      if (resource.status !== 1)
        continue;
      const allResourceIds = [
        ...resource.default_resource || [],
        ...resource.optional_resource || []
      ];
      for (const resId of allResourceIds) {
        const existing = map.get(resId);
        const mapping = {
          productId: product.id,
          productTitle: product.title,
          resourceName: resource.title,
          formId: resource.id,
          price: product.price || "0.00",
          resourceType: resource.type || "single"
        };
        if (!existing) {
          map.set(resId, [mapping]);
        } else if (!existing.some((m) => m.productId === mapping.productId)) {
          existing.push(mapping);
        }
      }
    }
  }
  return map;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  buildResourceProductMap,
  extractResourceIds
});
