#include <catch2/catch_test_macros.hpp>
#include <fmt/core.h>
#include <string>
#include "rand.hpp"
#include <nlohmann/json.hpp>
#include <fstream>
#include "components.hpp"
#include "inventory.hpp"
#include "dinkyecs.hpp"
#include "save.hpp"
#include "systems.hpp"

using namespace nlohmann;
using namespace fmt;
using std::string;
using namespace components;


DinkyECS::Entity add_items(components::ComponentMap component_map, DinkyECS::World &world, GameConfig &config) {
  auto sword = world.entity();
  json& item_data = config.items["SWORD_RUSTY"];
  world.set<InventoryItem>(sword, {item_data["inventory_count"], item_data});
  components::configure_entity(component_map, world, sword, item_data);
  return sword;
}

TEST_CASE("basic inventory test", "[inventory]") {
  // BUG: rewrite this
  /*
  DinkyECS::World world;
  save::load_configs(world);
  auto& config = world.get_the<GameConfig>();
  auto sword = add_items(world, config);

  auto player = world.entity();
  world.set<Inventory>(player, {});

  auto &inventory = world.get<Inventory>(player);

  System::pickup(world, player, sword);
  REQUIRE(inventory.count() == 1);
  // get the item and confirm there is 1
  auto &item1 = inventory.get(0);
  REQUIRE(item1.count == 1);

  int item_at = inventory.item_index("SWORD_RUSTY");
  REQUIRE(item_at == 0);

  REQUIRE(inventory.item_index("SADFASFSADF") == -1);

  System::pickup(world, player, sword);
  REQUIRE(item1.count == 2);

  System::pickup(world, player, sword);
  REQUIRE(item1.count == 3);

  System::pickup(world, player, sword);
  REQUIRE(inventory.count() == 1);

  REQUIRE(item1.count == 4);

  inventory.decrease(0, 1);
  REQUIRE(item1.count == 3);

  inventory.decrease(0, 2);
  REQUIRE(item1.count == 1);

  bool active = inventory.decrease(0, 1);
  REQUIRE(item1.count == 0);
  REQUIRE(active == false);

  inventory.erase_item(0);
  REQUIRE(inventory.count() == 0);
  */
}
