const MAX_TIMING_ENTRIES = 200;
const GLOBAL_KEY = "__openMercatoEnricherTimingEntries__";
const isDev = process.env.NODE_ENV === "development";
function getStore() {
  const existing = globalThis[GLOBAL_KEY];
  if (Array.isArray(existing)) return existing;
  const store = [];
  globalThis[GLOBAL_KEY] = store;
  return store;
}
function getEnricherTimingEntries() {
  return getStore();
}
function clearEnricherTimingEntries() {
  ;
  globalThis[GLOBAL_KEY] = [];
}
function addTimingEntry(entry) {
  const store = getStore();
  store.push(entry);
  if (store.length > MAX_TIMING_ENTRIES) {
    const trimmed = store.slice(-MAX_TIMING_ENTRIES);
    globalThis[GLOBAL_KEY] = trimmed;
  }
}
function logEnricherTiming(enricherId, moduleId, targetEntity, durationMs) {
  if (!isDev) return;
  addTimingEntry({
    enricherId,
    moduleId,
    targetEntity,
    durationMs,
    timestamp: Date.now()
  });
}
async function withEnricherTiming(enricherId, moduleId, targetEntity, fn) {
  if (!isDev) return fn();
  const start = performance.now();
  try {
    return await fn();
  } finally {
    const durationMs = Math.round(performance.now() - start);
    logEnricherTiming(enricherId, moduleId, targetEntity, durationMs);
  }
}
export {
  clearEnricherTimingEntries,
  getEnricherTimingEntries,
  logEnricherTiming,
  withEnricherTiming
};
//# sourceMappingURL=enricher-timing.js.map
