#include <catch2/catch_test_macros.hpp>
#include <iostream>
#include "rituals.hpp"
#include "fsm.hpp"
#include "dinkyecs.hpp"

using namespace combat;


TEST_CASE("cause scared rat won't run away bug", "[combat]") {
  ai::reset();
  ai::init("assets/ai.json");

  auto ai_start = ai::load_state("Enemy::initial_state");
  auto ai_goal = ai::load_state("Enemy::final_state");
  BattleEngine battle;

  DinkyECS::Entity rat_id = 1;
  ai::EntityAI rat("Enemy::actions", ai_start, ai_goal);
  rat.set_state("tough_personality", false);
  rat.set_state("health_good", true);
  battle.add_enemy(rat_id, rat);

  // first confirm that everyone stops fightings
  bool active = battle.plan();
  rat.dump();
  REQUIRE(active);
  REQUIRE(rat.wants_to("kill_enemy"));

  // this causes the plan to read END but if you set
  // health_good to false it will run_away

  rat.set_state("health_good", false);
  active = battle.plan();
  rat.dump();
  REQUIRE(rat.wants_to("run_away"));
}

TEST_CASE("battle operations fantasy", "[combat]") {
  ai::reset();
  ai::init("assets/ai.json");

  auto ai_start = ai::load_state("Enemy::initial_state");
  auto ai_goal = ai::load_state("Enemy::final_state");

  DinkyECS::Entity enemy_id = 0;
  ai::EntityAI enemy("Enemy::actions", ai_start, ai_goal);
  enemy.set_state("tough_personality", true);
  enemy.set_state("health_good", true);

  BattleEngine battle;
  battle.add_enemy(enemy_id, enemy);

  // responsible for running the AI and determining:
  // 1. Which enemy gets to go.
  // 2. What they want to do.
  battle.plan();

  // Then it will go through each in order and
  // have them fight, producing the results
  battle.fight([&](auto, auto& entity_ai) {
    entity_ai.dump();
  });
}