#include "components.hpp"

namespace components {
  void configure(DinkyECS::World &world, DinkyECS::Entity entity, json& entity_data) {
    for(auto &comp : entity_data["components"]) {
      json& config = comp["config"];
      const string comp_type = comp["type"];

      if(comp_type == "Weapon") {
        world.set<Weapon>(entity, {config["damage"]});
      } else if(comp_type == "LightSource") {
        world.set<LightSource>(entity, {config["strength"], config["radius"]});
      } else if(comp_type == "Loot") {
        world.set<Loot>(entity, {config["amount"]});
      } else if(comp_type == "Tile") {
        world.set<Tile>(entity, {config["chr"]});
      } else if(comp_type == "EnemyConfig") {
        world.set<EnemyConfig>(entity, {config["hearing_distance"]});
      } else if(comp_type == "Combat") {
        world.set<Combat>(entity, {config["hp"], config["damage"]});
      } else if(comp_type == "Curative") {
        world.set<Curative>(entity, {config["hp"]});
      } else if(comp_type == "Motion") {
        world.set<Motion>(entity, {config["dx"], config["dy"], config["random"]});
      } else if(comp_type == "Device") {
        Device device{.config=config, .events={}};
        device.configure_events(comp["events"]);
        world.set<Device>(entity, device);
      } else {
        dbc::sentinel(fmt::format("ITEM COMPONENT TYPE MISSING: {}",
              std::string(comp_type)));
      }

      // json config variable dies
    }
  }
}
