import {
  MS_PER_DAY
} from "./chunk-V6OJGLBA.js";

// ../memory/dist/decay/scoring.js
var DEFAULT_HALF_LIFE_MS = 30 * MS_PER_DAY;
var IMPORTANCE_BY_PRIORITY = {
  P0: 2,
  P1: 1.5,
  P2: 1,
  P3: 0.5
};
var DEFAULT_IMPORTANCE = 1;
function getNodeTimestamp(node) {
  const createdAt = new Date(node.created_at).getTime();
  if (!node.updated_at) {
    return createdAt;
  }
  const updatedAt = new Date(node.updated_at).getTime();
  return Math.max(createdAt, updatedAt);
}
function computeRecencyScore(node, halfLifeMs = DEFAULT_HALF_LIFE_MS, now = Date.now()) {
  const nodeTimestamp = getNodeTimestamp(node);
  const age = now - nodeTimestamp;
  return Math.exp(-age / halfLifeMs);
}
function computeAccessScore(node) {
  const accessCount = node.metadata?.access?.count ?? 0;
  return Math.log1p(accessCount) / 10;
}
function computeImportanceScore(node) {
  const priority = node.metadata?.priority;
  if (!priority) {
    return DEFAULT_IMPORTANCE;
  }
  return IMPORTANCE_BY_PRIORITY[priority] ?? DEFAULT_IMPORTANCE;
}
function computeDecayScore(node, options = {}) {
  const { now = Date.now(), halfLifeMs = DEFAULT_HALF_LIFE_MS } = options;
  const recencyScore = computeRecencyScore(node, halfLifeMs, now);
  const accessScore = computeAccessScore(node);
  const importanceScore = computeImportanceScore(node);
  return recencyScore * (1 + accessScore) * importanceScore;
}

export {
  DEFAULT_HALF_LIFE_MS,
  computeDecayScore
};
