#!/usr/bin/env node
import assert from "node:assert/strict";

import {
  DEPRECATED_DEV_PUBLIC_ENDPOINT,
  DEPRECATED_RESERVED_PROD_ENDPOINT,
  findDeprecatedPublicEndpoints,
  findForbiddenActiveDeprecatedEndpoints
} from "../internal/dev-report-lifecycle.mjs";

const activeReport = {
  reportLifecycle: {
    state: "active"
  }
};

const activeReportWithLegacyException = {
  reportLifecycle: {
    state: "active"
  },
  runtimeSmoke: {
    legacyPublicEndpoint: {
      endpoint: DEPRECATED_DEV_PUBLIC_ENDPOINT,
      status: "deprecated",
      activeGreenEligible: false
    }
  }
};

assert.deepEqual(
  findDeprecatedPublicEndpoints("current public endpoint http://74.48.78.17:6667/health"),
  [DEPRECATED_DEV_PUBLIC_ENDPOINT]
);
assert.deepEqual(
  findDeprecatedPublicEndpoints("old public :6666 evidence"),
  [DEPRECATED_RESERVED_PROD_ENDPOINT]
);
assert.deepEqual(
  findDeprecatedPublicEndpoints("http://hwlab-cloud-api.hwlab-dev.svc.cluster.local:6667 is an internal k3s service URL"),
  []
);
assert.deepEqual(
  findDeprecatedPublicEndpoints('"port": 6667, "note": "Internal k3s service port only"'),
  []
);
assert.deepEqual(
  findForbiddenActiveDeprecatedEndpoints(activeReport, "current public :6667 endpoint"),
  [DEPRECATED_DEV_PUBLIC_ENDPOINT]
);
assert.deepEqual(
  findForbiddenActiveDeprecatedEndpoints(activeReportWithLegacyException, "legacy public :6667 endpoint is deprecated"),
  []
);
assert.deepEqual(
  findForbiddenActiveDeprecatedEndpoints({ reportLifecycle: { state: "historical" } }, "current public :6667 endpoint"),
  []
);

console.log("validated report lifecycle endpoint scanner");
