-- Preload domain lines
local domains = {}
for line in io.lines("domains_1k.txt") do
  domains[#domains + 1] = '"' .. line .. '"'
end
local domains_len = #domains

-- Preallocate
local selected = {}
local seen = {}

local function pick_random_domains(n)
  -- Clear previous state
  for k in pairs(seen) do
    seen[k] = nil
  end

  local i = 1
  while i <= n do
    local idx = math.random(domains_len)
    if not seen[idx] then
      seen[idx] = true
      selected[i] = domains[idx]  -- Already quoted
      i = i + 1
    end
  end

  return "[" .. table.concat(selected, ",", 1, n) .. "]"
end

request = function()
  local n = math.random(2, 5)
  wrk.method = "POST"
  wrk.headers["Content-Type"] = "application/json"
  wrk.body = pick_random_domains(n)
  return wrk.format(nil)
end
