import { describe, expect, it } from "vitest";
import { catalogSampleLabels, matchIkCatalogItem } from "./ikCatalogMatcher";

const weapons = [
  { normalizedName: "favoniussword", good: "FavoniusSword" },
  { normalizedName: "skywardblade", good: "SkywardBlade" },
];
const characters = [
  { normalizedName: "furina", good: "Furina" },
  { normalizedName: "traveleranemo", good: "TravelerAnemo" },
];
const materials = [
  { normalizedName: "mora", good: "Mora" },
  { normalizedName: "heroswit", good: "HerosWit" },
];

describe("IK simple catalog matcher", () => {
  it("matches weapon names against IK GOOD keys", () => {
    const match = matchIkCatalogItem("Favonius Sword", weapons, "weapon");

    expect(match).toMatchObject({
      matched: true,
      category: "weapon",
      confidence: 100,
      good: "FavoniusSword",
      source: "ik-inventorylists",
    });
  });

  it("fuzzy-matches character names without inventing a category", () => {
    const match = matchIkCatalogItem("traveler anemo", characters, "character");

    expect(match.matched).toBe(true);
    expect(match.good).toBe("TravelerAnemo");
    expect(match.confidence).toBeGreaterThanOrEqual(78);
  });

  it("keeps unknown materials in review state", () => {
    const match = matchIkCatalogItem("not a real material", materials, "material");

    expect(match).toMatchObject({
      matched: false,
      category: "material",
      confidence: 0,
    });
    expect(match.notes[0]).toContain("not matched");
  });

  it("creates compact GOOD-key samples for UI catalog summaries", () => {
    expect(catalogSampleLabels([...weapons, ...characters], 3)).toEqual([
      "FavoniusSword",
      "SkywardBlade",
      "Furina",
    ]);
  });
});
