import assert from "node:assert/strict"
import { dedupFlowRowsMaxBytes, flowTupleKey } from "./traffic-flow-dedup.js"

const a = {
  serverId: 7,
  src: "10.1.1.8",
  dst: "8.8.8.8",
  proto: 6,
  srcPort: 1,
  dstPort: 443,
  inIface: "2",
  bytes: 12_000,
  packets: 10,
}
const b = { ...a, inIface: "10", bytes: 8_000, packets: 8 }
const out = dedupFlowRowsMaxBytes([a, b])
assert.equal(out.length, 1)
assert.equal(out[0]?.bytes, 12_000)
assert.equal(out[0]?.inIface, "2")
assert.equal(flowTupleKey(a), flowTupleKey(b))

const sameIface = dedupFlowRowsMaxBytes([a, { ...a, bytes: 3_000, packets: 2 }])
assert.equal(sameIface[0]?.bytes, 15_000)

console.log("traffic-flow-dedup.test.ts: ok")
