import { describe, expect, it } from "vitest";
import { HEALER_CLASS_ORDER } from "./healers";
import {
  createDefaultHealerAppearance,
  HEALER_VISUAL_PROFILES,
  healerVisualSignature,
  normalizeHealerAppearance,
} from "./healerVisuals";

describe("healer visual profiles", () => {
  it("covers every healer class", () => {
    expect(Object.keys(HEALER_VISUAL_PROFILES)).toEqual(HEALER_CLASS_ORDER);
  });

  it("reuses Aelia's animation rig for every healer body", () => {
    for (const profile of Object.values(HEALER_VISUAL_PROFILES)) {
      expect(profile.animationMemberId).toBe("aelia");
    }
  });

  it("gives every healer a distinct silhouette and loadout signature", () => {
    const signatures = Object.values(HEALER_VISUAL_PROFILES).map(healerVisualSignature);
    expect(new Set(signatures).size).toBe(HEALER_CLASS_ORDER.length);
  });

  it("returns owned defaults and repairs unknown saved appearances per class", () => {
    const first = createDefaultHealerAppearance("priest");
    const second = createDefaultHealerAppearance("priest");
    expect(first).toEqual(HEALER_VISUAL_PROFILES.priest.appearance);
    expect(first).not.toBe(second);
    expect(first.mainHand).not.toBe(second.mainHand);
    expect(normalizeHealerAppearance("druid", { version: 99 })).toEqual(
      HEALER_VISUAL_PROFILES.druid.appearance,
    );
  });

  it("upgrades the former mage-only priest default without replacing customized looks", () => {
    const legacyDefault = {
      version: 1,
      rigId: "medium",
      scaleSourceMemberId: "orin",
      headPartId: "mage-head",
      upperBodyPartId: "mage-upper",
      lowerBodyPartId: "mage-lower",
      headwearPartId: null,
      backPartId: "mage-cape",
      mainHand: { modelId: "cc/adv_druid_staff", grip: "staff" },
    };
    expect(normalizeHealerAppearance("priest", legacyDefault)).toEqual(
      HEALER_VISUAL_PROFILES.priest.appearance,
    );
    expect(normalizeHealerAppearance("priest", { ...legacyDefault, backPartId: null })).toMatchObject({
      headPartId: "mage-head",
      upperBodyPartId: "mage-upper",
      lowerBodyPartId: "mage-lower",
      backPartId: null,
    });
  });

  it("upgrades the sword-bearing Paladin default to mace and shield", () => {
    const legacyDefault = {
      version: 1,
      rigId: "medium",
      scaleSourceMemberId: "brann",
      headPartId: "knight-head",
      upperBodyPartId: "knight-upper",
      lowerBodyPartId: "knight-lower",
      headwearPartId: "knight-helmet",
      backPartId: "knight-cape",
      mainHand: { modelId: "cc/adv_sword_1handed", grip: "upright" },
      offHand: { modelId: "cc/shield_badge", grip: "prop" },
    };
    expect(normalizeHealerAppearance("paladin", legacyDefault)).toEqual(
      HEALER_VISUAL_PROFILES.paladin.appearance,
    );
    expect(HEALER_VISUAL_PROFILES.paladin.appearance).toMatchObject({
      mainHand: { modelId: "cc/hammer_a", grip: "upright" },
      offHand: { modelId: "cc/shield_badge", grip: "prop" },
    });
    expect(normalizeHealerAppearance("paladin", { ...legacyDefault, backPartId: null })).toMatchObject({
      backPartId: null,
      mainHand: { modelId: "cc/adv_sword_1handed" },
    });
  });
});
