const axios = require("axios");

function resolveConfig(bru) {
  return {
    baseUrl: bru.getEnvVar("baseUrl") || bru.getVar("baseUrl"),
    jsonHeaders: { headers: { "Content-Type": "application/json" } },
  };
}

async function resetPrototypeCombatTargets(bru) {
  const { baseUrl, jsonHeaders } = resolveConfig(bru);
  const response = await axios.post(
    `${baseUrl}/game/__dev/combat-targets-fixture`,
    { schemaVersion: 1 },
    jsonHeaders,
  );
  if (response.status !== 200 || response.data?.applied !== true) {
    throw new Error(
      `combat-targets fixture reset failed: ${response.status} ${JSON.stringify(response.data)}`,
    );
  }
}

module.exports = {
  resetPrototypeCombatTargets,
};
