/**
 * AchievementNotification Component Tests
 *
 * Tests the rarity classification and colour mapping logic used by the
 * AchievementNotification component.
 *
 * What this component does:
 * - Listens for "achievement:unlocked" Tauri events
 * - Queues and displays achievement notifications one at a time
 * - Each notification shows the achievement's name, icon, description, and rarity
 * - A gradient border and badge colour correspond to the achievement's rarity
 *
 * Manual testing checklist:
 * - [ ] Achievement notification slides in from the right
 * - [ ] Notification auto-dismisses after 5 seconds
 * - [ ] Dismiss button works immediately
 * - [ ] Multiple achievements queue and display sequentially
 * - [ ] Legendary achievements have a yellow-orange gradient
 * - [ ] Epic achievements have a purple-pink gradient
 * - [ ] Rare achievements have a blue-indigo gradient
 * - [ ] Common achievements have a green-emerald gradient
 */

import { describe, it, expect } from "vitest";

function getAchievementRarity(id: string): string {
  if (id === "TokenMaster") return "legendary";
  if (["CodeMachine", "Unstoppable"].includes(id)) return "epic";
  if (
    [
      "BlossomingCoder",
      "CodeWizard",
      "MasterBuilder",
      "EnduranceChamp",
      "DeepDive",
      "CreativeCoder",
    ].includes(id)
  )
    return "rare";
  return "common";
}

function getRarityColor(rarity: string): string {
  switch (rarity) {
    case "legendary":
      return "from-yellow-400 to-orange-500";
    case "epic":
      return "from-purple-400 to-pink-500";
    case "rare":
      return "from-blue-400 to-indigo-500";
    default:
      return "from-green-400 to-emerald-500";
  }
}

// ---

describe("getAchievementRarity", () => {
  describe("legendary tier", () => {
    it("classifies TokenMaster as legendary", () => {
      expect(getAchievementRarity("TokenMaster")).toBe("legendary");
    });
  });

  describe("epic tier", () => {
    it("classifies CodeMachine as epic", () => {
      expect(getAchievementRarity("CodeMachine")).toBe("epic");
    });

    it("classifies Unstoppable as epic", () => {
      expect(getAchievementRarity("Unstoppable")).toBe("epic");
    });
  });

  describe("rare tier", () => {
    it("classifies BlossomingCoder as rare", () => {
      expect(getAchievementRarity("BlossomingCoder")).toBe("rare");
    });

    it("classifies CodeWizard as rare", () => {
      expect(getAchievementRarity("CodeWizard")).toBe("rare");
    });

    it("classifies MasterBuilder as rare", () => {
      expect(getAchievementRarity("MasterBuilder")).toBe("rare");
    });

    it("classifies EnduranceChamp as rare", () => {
      expect(getAchievementRarity("EnduranceChamp")).toBe("rare");
    });

    it("classifies DeepDive as rare", () => {
      expect(getAchievementRarity("DeepDive")).toBe("rare");
    });

    it("classifies CreativeCoder as rare", () => {
      expect(getAchievementRarity("CreativeCoder")).toBe("rare");
    });
  });

  describe("common tier", () => {
    it("classifies unknown IDs as common", () => {
      expect(getAchievementRarity("FirstChat")).toBe("common");
      expect(getAchievementRarity("SomeNewAchievement")).toBe("common");
      expect(getAchievementRarity("")).toBe("common");
    });
  });
});

describe("getRarityColor", () => {
  it("returns yellow-to-orange gradient for legendary", () => {
    expect(getRarityColor("legendary")).toBe("from-yellow-400 to-orange-500");
  });

  it("returns purple-to-pink gradient for epic", () => {
    expect(getRarityColor("epic")).toBe("from-purple-400 to-pink-500");
  });

  it("returns blue-to-indigo gradient for rare", () => {
    expect(getRarityColor("rare")).toBe("from-blue-400 to-indigo-500");
  });

  it("returns green-to-emerald gradient for common", () => {
    expect(getRarityColor("common")).toBe("from-green-400 to-emerald-500");
  });

  it("falls back to green-to-emerald gradient for unknown rarities", () => {
    expect(getRarityColor("mythic")).toBe("from-green-400 to-emerald-500");
    expect(getRarityColor("")).toBe("from-green-400 to-emerald-500");
  });

  describe("end-to-end rarity pipeline", () => {
    it("produces the correct colour for a legendary achievement", () => {
      const color = getRarityColor(getAchievementRarity("TokenMaster"));
      expect(color).toBe("from-yellow-400 to-orange-500");
    });

    it("produces the correct colour for an epic achievement", () => {
      const color = getRarityColor(getAchievementRarity("CodeMachine"));
      expect(color).toBe("from-purple-400 to-pink-500");
    });

    it("produces the correct colour for a rare achievement", () => {
      const color = getRarityColor(getAchievementRarity("CodeWizard"));
      expect(color).toBe("from-blue-400 to-indigo-500");
    });

    it("produces the correct colour for a common achievement", () => {
      const color = getRarityColor(getAchievementRarity("FirstChat"));
      expect(color).toBe("from-green-400 to-emerald-500");
    });
  });
});
