import { describe, expect, it } from "vitest";
import { createDefaultHealerAppearance } from "./healerVisuals";
import { heldItemForModel, weaponDefinitionsForSlot } from "./weaponCatalog";
import { resolveCharacterEquipment } from "./characterEquipment";

describe("character equipment resolution", () => {
  it("hides but never deletes a saved offhand behind a two-handed weapon", () => {
    const appearance = {
      ...createDefaultHealerAppearance("paladin"),
      mainHand: heldItemForModel("cc/staff_d"),
    };
    const resolved = resolveCharacterEquipment(appearance);
    expect(resolved.offHand).toBeUndefined();
    expect(appearance.offHand).toEqual(heldItemForModel("cc/shield_badge"));

    const restored = resolveCharacterEquipment({
      ...appearance,
      mainHand: heldItemForModel("cc/adv_sword_1handed"),
    });
    expect(restored.offHand).toEqual(appearance.offHand);
  });

  it("pairs every crossbow with the loose Claudecraft quiver only at render time", () => {
    const base = createDefaultHealerAppearance("priest");
    const crossbows = weaponDefinitionsForSlot("main").filter((entry) => entry.category === "crossbow");
    expect(crossbows).toHaveLength(3);
    for (const crossbow of crossbows) {
      const appearance = { ...base, mainHand: heldItemForModel(crossbow.id) };
      expect(resolveCharacterEquipment(appearance)).toMatchObject({
        backPropModelId: "cc/quiver",
        suppressSkinnedBack: true,
      });
      expect(appearance.backPartId).toBe(base.backPartId);
    }
    expect(resolveCharacterEquipment(base).backPropModelId).toBeUndefined();
  });
});
