import { expect } from "@esm-bundle/chai";
import { Item } from "../../src/items/Item.js";

// Mock Unit for Requirement Checking
const mockVanguard = {
  activeClassId: "CLASS_VANGUARD",
  baseStats: { attack: 10, tech: 0 },
};

const mockTinker = {
  activeClassId: "CLASS_TINKER",
  baseStats: { attack: 5, tech: 10 },
};

describe("System: Items", () => {
  let swordDef;
  let techGunDef;

  beforeEach(() => {
    swordDef = {
      id: "ITEM_TEST_SWORD",
      name: "Test Sword",
      type: "WEAPON",
      stats: { attack: 5 },
      requirements: { min_stat: { attack: 8 } },
    };

    techGunDef = {
      id: "ITEM_TEST_GUN",
      type: "WEAPON",
      stats: { attack: 8 },
      requirements: { class_lock: ["CLASS_TINKER"] },
    };
  });

  it("CoA 1: Should store basic stats correctly", () => {
    const item = new Item(swordDef);
    expect(item.getStat("attack")).to.equal(5);
    expect(item.getStat("magic")).to.equal(0); // Undefined stat
  });

  it("CoA 2: Should enforce Min Stat requirements", () => {
    const item = new Item(swordDef);

    // Vanguard has 10 Atk (Passes > 8)
    expect(item.canEquip(mockVanguard)).to.be.true;

    // Tinker has 5 Atk (Fails < 8)
    expect(item.canEquip(mockTinker)).to.be.false;
  });

  it("CoA 3: Should enforce Class Lock requirements", () => {
    const item = new Item(techGunDef);

    // Vanguard cannot equip Tinker items
    expect(item.canEquip(mockVanguard)).to.be.false;

    // Tinker can
    expect(item.canEquip(mockTinker)).to.be.true;
  });

  it("CoA 4: Should handle Active Ability grants", () => {
    const kitDef = {
      id: "ITEM_KIT",
      type: "UTILITY",
      active_ability: { ability_id: "SKILL_DEPLOY" },
    };
    const item = new Item(kitDef);

    expect(item.activeAbility).to.exist;
    expect(item.activeAbility.ability_id).to.equal("SKILL_DEPLOY");
  });
});
