import {
  log
} from "./chunk-2ODBA7MQ.js";

// src/recall-qos.ts
function defaultTiming(metric) {
  if (typeof metric.timing === "string" && metric.timing.length > 0) {
    return metric.timing;
  }
  if (metric.source === "skip") {
    return "skip";
  }
  return `${Math.max(0, Math.round(metric.durationMs))}ms`;
}
function formatRecallSectionMetric(metric) {
  const payload = {
    section: metric.section,
    priority: metric.priority,
    durationMs: metric.durationMs,
    deadlineMs: metric.deadlineMs,
    source: metric.source,
    success: metric.success
  };
  return {
    message: "recall section metric",
    payload,
    level: metric.priority === "core" && metric.success && metric.source !== "skip" ? "info" : "debug",
    timing: defaultTiming(metric)
  };
}
function createRecallSectionMetricRecorder(options = {}) {
  const logger = options.logger ?? log;
  return (metric) => {
    const entry = formatRecallSectionMetric(metric);
    if (options.timings) {
      options.timings[metric.section] = entry.timing;
    }
    if (entry.level === "info") {
      if (typeof logger.info === "function") {
        logger.info(entry.message, entry.payload);
      } else {
        log.info(entry.message, entry.payload);
      }
    } else {
      if (typeof logger.debug === "function") {
        logger.debug(entry.message, entry.payload);
      } else {
        log.debug(entry.message, entry.payload);
      }
    }
    return entry;
  };
}

export {
  formatRecallSectionMetric,
  createRecallSectionMetricRecorder
};
//# sourceMappingURL=chunk-7DHTMOND.js.map