import assert from "node:assert/strict";
import { assertBatchTimeBounds, rawRetentionExpiry } from "../src/intake-policy.mjs";

const now = new Date("2026-07-15T12:00:00.000Z");
const batch = {
  batch: { receivedAt: "2026-07-15T12:04:59.000Z" },
  facts: [{ observedAt: "2026-07-15T12:05:00.000Z" }],
};

assert.doesNotThrow(() => assertBatchTimeBounds(batch, { now, maxFutureSkewSeconds: 300 }));
assert.throws(() => assertBatchTimeBounds({
  ...batch,
  batch: { receivedAt: "2026-07-15T12:05:01.000Z" },
}, { now, maxFutureSkewSeconds: 300 }), /batch_received_at_too_far_in_future/);
assert.throws(() => assertBatchTimeBounds({
  ...batch,
  facts: [{ observedAt: "2026-07-15T12:05:01.000Z" }],
}, { now, maxFutureSkewSeconds: 300 }), /fact_observed_at_too_far_in_future/);

assert.equal(
  rawRetentionExpiry({ now, rawRetentionDays: 14 }).toISOString(),
  "2026-07-29T12:00:00.000Z",
);
assert.throws(() => rawRetentionExpiry({ now, rawRetentionDays: 0 }), /raw_retention_days_invalid/);

console.log("external-data-plane intake policy: ok");
