import { describe, expect, it } from "vitest";
import { ARENA_CENTER } from "./arena";
import { AVAILABLE_BOSS_IDS } from "./bossCatalog";
import { advanceBossMechanics, createBossMotionState, createBossState } from "./bossMechanics";
import { freshParty } from "./data";
import type { WorldPosition } from "./types";

const PARTY_POSITIONS = {
  aelia: [0, 4.5],
  brann: [7, 5],
  nia: [-3, 2],
  orin: [3, 2],
  vale: [0, -2],
} satisfies Record<"aelia" | "brann" | "nia" | "orin" | "vale", WorldPosition>;

describe("boss home positioning", () => {
  it.each(AVAILABLE_BOSS_IDS)("moves %s back toward its center slot while idle", (bossId) => {
    const motion = createBossMotionState(bossId);
    motion.position = [7, 5];
    motion.nextMechanicAt = Number.POSITIVE_INFINITY;
    const before = Math.hypot(
      motion.position[0] - (ARENA_CENTER[0] + motion.formationOffsetX),
      motion.position[1] - ARENA_CENTER[1],
    );

    const result = advanceBossMechanics({
      boss: createBossState(bossId),
      motion,
      party: freshParty(),
      partyPositions: structuredClone(PARTY_POSITIONS),
      time: 0,
      delta: 0.5,
      damageMember: (member) => member,
    });
    const after = Math.hypot(
      result.motion.position[0] - (ARENA_CENTER[0] + result.motion.formationOffsetX),
      result.motion.position[1] - ARENA_CENTER[1],
    );

    expect(after).toBeLessThan(before);
  });
});
