meta {
  name: GET combat targets after one cast (NEO-83)
  type: http
  seq: 2
}

docs {
  Fast cast→GET smoke: one pulse on alpha, no cooldown waits. Four-pulse defeat spine is seq 3.
}

script:pre-request {
  const axios = require("axios");
  const { resetPrototypeCombatTargets } = require("./scripts/combat-targets-reset-helper.js");
  const baseUrl = bru.getEnvVar("baseUrl") || bru.getVar("baseUrl");
  const playerId = bru.getEnvVar("playerId") || bru.getVar("playerId");
  const jsonHeaders = { headers: { "Content-Type": "application/json" } };

  await resetPrototypeCombatTargets(bru);

  await axios.post(
    `${baseUrl}/game/players/${playerId}/move`,
    { schemaVersion: 1, target: { x: -5, y: 0.9, z: -5 } },
    jsonHeaders,
  );

  await axios.post(
    `${baseUrl}/game/players/${playerId}/hotbar-loadout`,
    {
      schemaVersion: 1,
      slots: [{ slotIndex: 0, abilityId: "prototype_pulse" }],
    },
    jsonHeaders,
  );

  await axios.post(
    `${baseUrl}/game/players/${playerId}/target/select`,
    { schemaVersion: 1, targetId: "prototype_target_alpha" },
    jsonHeaders,
  );

  const castResponse = await axios.post(
    `${baseUrl}/game/players/${playerId}/ability-cast`,
    {
      schemaVersion: 1,
      slotIndex: 0,
      abilityId: "prototype_pulse",
      targetId: "prototype_target_alpha",
    },
    jsonHeaders,
  );

  const castBody = castResponse.data;
  if (!castBody?.accepted || !castBody?.combatResolution) {
    throw new Error(`neo83 one-pulse cast failed: ${JSON.stringify(castBody)}`);
  }

  bru.setVar("neo83OnePulseCast", JSON.stringify(castBody));
}

get {
  url: {{baseUrl}}/game/world/combat-targets
  body: none
  auth: none
}

tests {
  test("one-pulse cast body shows 75 HP remaining", function () {
    const castBody = JSON.parse(bru.getVar("neo83OnePulseCast"));
    expect(castBody.combatResolution.targetRemainingHp).to.equal(75);
    expect(castBody.combatResolution.targetDefeated).to.equal(false);
  });

  test("GET alpha reflects cast damage authoritatively", function () {
    const body = res.getBody();
    const alpha = body.targets.find(
      (x) => x.targetId === "prototype_target_alpha",
    );
    expect(alpha).to.be.an("object");
    expect(alpha.currentHp).to.equal(75);
    expect(alpha.maxHp).to.equal(100);
    expect(alpha.defeated).to.equal(false);
  });

  test("beta unchanged after alpha-only cast", function () {
    const body = res.getBody();
    const beta = body.targets.find(
      (x) => x.targetId === "prototype_target_beta",
    );
    expect(beta).to.be.an("object");
    expect(beta.currentHp).to.equal(100);
    expect(beta.defeated).to.equal(false);
  });
}
