import { EasyEvent } from "@24tools/playable_template";
import { ResourceType } from "./ResourceType";

export class ResourceInventoryC {
  private static amounts = new Map<ResourceType, number>();
  static readonly onChanged = new EasyEvent<{ type: ResourceType }>();

  static get(type: ResourceType) {
    return this.amounts.get(type) ?? 0;
  }

  static add(type: ResourceType, amount: number) {
    if (amount <= 0) return;
    this.amounts.set(type, this.get(type) + amount);
    this.onChanged.Invoke({ type });
  }

  static remove(type: ResourceType, amount: number) {
    if (amount <= 0) return;
    this.amounts.set(type, Math.max(0, this.get(type) - amount));
    this.onChanged.Invoke({ type });
  }
}
