export class CardManager {
  constructor(cardsData) {
    this.cards = new Map(cardsData.map(c => [c.id, c]));
  }

  getCard(id) {
    return this.cards.get(id) || null;
  }

  getAllCards() {
    return [...this.cards.values()];
  }

  getByFaction(faction) {
    return this.getAllCards().filter(c => c.faction === faction);
  }

  getByType(type) {
    return this.getAllCards().filter(c => c.type === type);
  }

  getByRarity(rarity) {
    return this.getAllCards().filter(c => c.rarity === rarity);
  }

  createInstance(id) {
    const base = this.getCard(id);
    if (!base) return null;
    return {
      ...base,
      skills: base.skills.map(s => ({ ...s })),
      currentHP: base.health,
      currentAttack: base.attack,
      currentArmor: base.armor,
      currentDelay: base.delay,
      ruptureStacks: 0,
      jamTurns: 0,
      berserkBonus: 0,
      instanceId: Math.random().toString(36).slice(2)
    };
  }
}
