${
  [1].map(() => {
    const dc = location.search.dc;

    // NOTE!!! The logic below to pick the upstream/downstream service
    // names must exactly match the logic in internal/ui/metrics-proxy/.../query
    // If you change this, change it there too!

    // Pick a number of down/upstreams to return based on the cookie variable.
    // If you change anything about this variable or it's default, you'll need
    // to change the topology endpoint to match.
    var numUp = env("CONSUL_UPSTREAM_COUNT", 3);
    var numDown = env("CONSUL_DOWNSTREAM_COUNT", 5);

    var genFakeServiceNames = function(num) {
      // Seed faker by the number of results we want to make it deterministic
      // here and in other correlated endpoints.
      fake.seed(num);
      var serviceNames = [];
      for (var i = 0; i < num; i++) {
        serviceNames.push(`service-${fake.random.number({min:0, max:99})}`)
      }
      return serviceNames
    };

    var upstreams = genFakeServiceNames(numUp);
    var downstreams = genFakeServiceNames(numDown);

    const targetService = location.pathname.toString().replace('/v1/internal/ui/service-topology/', '')

    // little helper to get a deterministic number from the target service
    // name string. NOTE: this should be the same as in metrics-proxy/.../query
    // endpoint so metrics match what is requested.
    var hashStr = function(s) {
      for(var i = 0, h = 0xdeadbeef; i < s.length; i++)
          h = Math.imul(h ^ s.charCodeAt(i), 2654435761);
      return (h ^ h >>> 16) >>> 0;
    };

    var serviceProto = "tcp"
    // Randomly pick the serviceProtocol which will affect which types of
    // stats we return for downstream clusters. But we need it to be
    // deterministic for a given service name so that all the downstream
    // stats are consistently typed.
    fake.seed(hashStr(targetService))
    if (fake.random.number(1) > 0.5) {
      serviceProto = "http";
    }

    return `
{
  "Protocol": "${serviceProto}",
  "FilteredByACLs": ${fake.random.boolean()},
  "Upstreams":
  [
    ${
      upstreams.map((item, i) => {
        let hasPerms = fake.random.boolean();
        // if hasPerms is true allowed is always false as some restrictions apply
        let allowed = hasPerms ? false : fake.random.boolean();
        return `
    {
      "Name": "${item}",
      "Datacenter": "${dc}",
  ${i === 1 ? `
        "Namespace": "default",
  ` : `
        "Namespace": "${fake.hacker.noun()}-ns-${i}",
  `}
      "ChecksPassing":${fake.random.number({min: 1, max: env('CONSUL_CHECK_COUNT', fake.random.number(10))})},
      "ChecksWarning":${fake.random.number({min: 0, max: env('CONSUL_CHECK_COUNT', fake.random.number(10))})},
      "ChecksCritical":${fake.random.number({min: 0, max: env('CONSUL_CHECK_COUNT', fake.random.number(10))})},
      "Intention": {
        "Allowed": ${allowed},
        "HasPermissions": ${hasPerms},
        "ExternalSource": "${fake.helpers.randomize(['nomad', 'kubernetes', ''])}",
        "HasExact": ${fake.random.boolean()}
      }
    }
    `})}
  ],
  "Downstreams":
  [
    ${
      downstreams.map((item, i) => {
        let hasPerms = fake.random.boolean();
        // if hasPerms is true allowed is always false as some restrictions apply
        let allowed = hasPerms ? false : fake.random.boolean();
        return `
    {
      "Name": "${item}",
      "Datacenter": "${dc}",
  ${i === 1 ? `
        "Namespace": "default",
  ` : `
        "Namespace": "${fake.hacker.noun()}-ns-${i}",
  `}
      "ChecksPassing":${fake.random.number({min: 1, max: env('CONSUL_CHECK_COUNT', fake.random.number(10))})},
      "ChecksWarning":${fake.random.number({min: 0, max: env('CONSUL_CHECK_COUNT', fake.random.number(10))})},
      "ChecksCritical":${fake.random.number({min: 0, max: env('CONSUL_CHECK_COUNT', fake.random.number(10))})},
      "Intention": {
        "Allowed": ${allowed},
        "HasPermissions": ${hasPerms},
        "ExternalSource": "${fake.helpers.randomize(['nomad', 'kubernetes', ''])}",
        "HasExact": ${fake.random.boolean()}
      }
    }
    `})}
  ]
}`

  })
}