#pragma once
#include "ai.hpp"
#include "gui/fsm.hpp"
#include <guecs/ui.hpp>

struct InventoryStats;

struct Autowalker {
  int enemy_count = 0;
  int item_count = 0;
  int device_count = 0;
  bool map_opened_once = false;
  bool weapon_crafted = false;
  gui::FSM& fsm;
  std::shared_ptr<Raycaster> rayview;

  Autowalker(gui::FSM& fsm)
    : fsm(fsm), rayview(fsm.$main_ui.$rayview) {}

  void autowalk();
  void start_autowalk();
  void craft_weapon();
  void open_map();
  void close_map();
  bool found_enemy();
  bool found_item();

  void handle_window_events();
  void handle_boss_fight();
  void handle_player_walk(ai::State& start, ai::State& goal);

  void send_event(gui::Event ev, std::any data={});
  void process_combat();
  bool process_move(Pathing& paths, std::function<bool(Point)> cb);
  bool path_player(Pathing& paths, Point &target_out);
  void path_fail(const std::string& msg, Matrix& bad_paths, Point pos);
  void rotate_player(Point target);
  void log(std::wstring msg);
  void status(std::wstring msg);
  void close_status();
  bool player_health_good();
  void player_use_healing();
  InventoryStats player_item_count();
  void update_state(ai::EntityAI& player_ai);
  DinkyECS::Entity camera_aim();

  Pathing path_to_enemies();
  Pathing path_to_items();
  void face_target(Point target);
  bool face_enemy();
  void pickup_item();
  void pocket_potion(GameDB::Level &level);
  void click_inventory(const std::string& name, guecs::Modifiers mods);
};
