import { describe, expect, it } from "vitest";
import { matchPiece, matchSet, matchSlot, matchStat, validateLookupPackage } from "./genshinLookup";
import { genshinGameData } from "./genshinData";

describe("genshinLookup", () => {
  it("matches canonical, alias, and fuzzy artifact values", () => {
    expect(matchSlot("Sands of Eon Vi")).toMatchObject({ value: "Sands of Eon", source: "alias" });
    expect(matchSet("Viridescent Venere")).toMatchObject({ value: "Viridescent Venerer", source: "alias" });
    expect(matchPiece("Viridescent Venerers Determination").value).toBe("Viridescent Venerer's Determination");
    expect(matchStat("Crit Damage")).toMatchObject({ value: "CRIT DMG", source: "alias" });
  });

  it("validates the bundled lookup package", () => {
    const status = validateLookupPackage();
    expect(status.valid).toBe(true);
    expect(status.errors).toEqual([]);
    expect(status.summary.artifactPieces).toBeGreaterThan(0);
  });

  it("rejects missing set references", () => {
    const broken = {
      ...genshinGameData,
      artifactPieces: [{ name: "Broken Piece", setName: "Missing Set", slot: "Flower of Life", relicType: "EQUIP_BRACER" }],
    };
    const status = validateLookupPackage(broken as unknown as typeof genshinGameData);
    expect(status.valid).toBe(false);
    expect(status.errors.join("\n")).toContain("Missing Set");
  });

  it("rejects duplicate GOOD set keys", () => {
    const broken = {
      ...genshinGameData,
      lookup: {
        ...genshinGameData.lookup,
        goodKeys: {
          ...genshinGameData.lookup?.goodKeys,
          sets: {
            one: "Duplicate",
            two: "Duplicate",
          },
        },
      },
    };
    const status = validateLookupPackage(broken as unknown as typeof genshinGameData);
    expect(status.valid).toBe(false);
    expect(status.errors.join("\n")).toContain("Duplicate GOOD set key");
  });
});
