'use strict';

// src/platform/token-optimizer/deduplication.ts
var NORMALIZATION_RULES = [
  // ISO 타임스탬프 (2026-04-09T10:00:01.123 또는 2026-04-09 10:00:01)
  [/\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}[.\d]*/g, "<TIMESTAMP>"],
  // 대괄호 타임스탬프 ([10:00:01], [2026-04-09 10:00:01])
  [/\[\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}[.\d]*\]/g, "[<TIMESTAMP>]"],
  // UUID
  [/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi, "<UUID>"],
  // IP 주소
  [/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/g, "<IP>"],
  // 16진수 해시 (7자 이상)
  [/\b[0-9a-f]{7,}\b/gi, "<HEX>"],
  // 큰 숫자 (4자리 이상)
  [/\b\d{4,}\b/g, "<NUM>"]
];
var normalizeLine = (line) => {
  let normalized = line;
  for (const [pattern, replacement] of NORMALIZATION_RULES) {
    normalized = normalized.replace(pattern, replacement);
  }
  return normalized;
};
var deduplicateLines = (text) => {
  const lines = text.split("\n");
  const groups = /* @__PURE__ */ new Map();
  const orderedKeys = [];
  for (const line of lines) {
    if (line.trim().length === 0) {
      const emptyKey = `__EMPTY_${orderedKeys.length}__`;
      groups.set(emptyKey, { count: 1, originalLine: line });
      orderedKeys.push(emptyKey);
      continue;
    }
    const normalized = normalizeLine(line);
    if (groups.has(normalized)) {
      groups.get(normalized).count += 1;
    } else {
      groups.set(normalized, { count: 1, originalLine: line });
      orderedKeys.push(normalized);
    }
  }
  return orderedKeys.map((key) => {
    const group = groups.get(key);
    if (group.count > 1) {
      return `[x${group.count}] ${normalizeLine(group.originalLine)}`;
    }
    return group.originalLine;
  }).join("\n");
};

exports.deduplicateLines = deduplicateLines;
