import { describe, expect, it } from "vitest";
import { AVAILABLE_BOSS_IDS } from "../bossCatalog";
import { createClassInventory } from "../healers";
import { useGameStore } from "../store";
import type { BossId } from "../types";
import { rpgEncounterDifficulty } from "./difficulty";

function simulateSoloBoss(bossId: BossId, maxSeconds = 120): number {
  useGameStore.getState().configureHealer(
    "priest",
    "Calibration",
    createClassInventory("priest"),
    bossId,
    "encounter",
  );
  useGameStore.getState().startEncounter();
  const profile = rpgEncounterDifficulty("boss-room", 0);
  useGameStore.setState((state) => {
    const maxHp = Math.round(state.boss.maxHp * profile.healthMultiplier);
    return { boss: { ...state.boss, maxHp, hp: maxHp } };
  });

  while (useGameStore.getState().phase === "combat" && useGameStore.getState().time < maxSeconds) {
    useGameStore.setState((state) => ({
      party: state.party.map((member) => ({ ...member, hp: member.maxHp, absorb: 10_000 })),
    }));
    useGameStore.getState().tick(0.1);
  }

  return useGameStore.getState().time;
}

describe("RPG Roguelike solo boss duration calibration", () => {
  it.each(AVAILABLE_BOSS_IDS)("keeps %s near the two-boss rotation duration budget", (bossId) => {
    const duration = simulateSoloBoss(bossId);
    expect(useGameStore.getState().phase).toBe("victory");
    expect(duration).toBeGreaterThanOrEqual(50);
    // Shared baseline targets 50–90 seconds, with 100 seconds as the hard cap.
    expect(duration).toBeLessThanOrEqual(100);
  });
});
