const MAX_SAMPLES = 50;
const COST_THRESHOLD = 25;
const expensiveQueries = [];
const recentViolations = [];
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
let totalRecorded = 0;
let totalViolations = 0;
let totalExpensive = 0;
function recordDeliveryQuery(input) {
  totalRecorded += 1;
  const timestamp = (/* @__PURE__ */ new Date()).toISOString();
  if (input.cost.total >= COST_THRESHOLD) {
    totalExpensive += 1;
    expensiveQueries.unshift({
      timestamp,
      route: input.route,
      method: input.method,
      cost: input.cost,
      warningCount: input.warnings.length
    });
    if (expensiveQueries.length > MAX_SAMPLES) {
      expensiveQueries.length = MAX_SAMPLES;
    }
  }
  if (input.warnings.length > 0) {
    for (const warning of input.warnings) {
      totalViolations += 1;
      recentViolations.unshift({
        timestamp,
        route: input.route,
        method: input.method,
        field: warning.field,
        message: warning.message,
        limit: warning.limit,
        actual: warning.actual
      });
    }
    if (recentViolations.length > MAX_SAMPLES) {
      recentViolations.length = MAX_SAMPLES;
    }
  }
}
function getDeliveryMetrics() {
  return {
    costThreshold: COST_THRESHOLD,
    bufferLimit: MAX_SAMPLES,
    expensiveQueries: [...expensiveQueries],
    recentViolations: [...recentViolations],
    totals: {
      totalRecorded,
      totalViolations,
      expensiveQueries: totalExpensive
    },
    startedAt
  };
}

export { getDeliveryMetrics as g, recordDeliveryQuery as r };
//# sourceMappingURL=delivery-metrics.mjs.map
