#pragma once
#include <vector>
#include <unordered_map>
#include "map.hpp"
#include "dinkyecs.hpp"
#include "point.hpp"

typedef std::vector<DinkyECS::Entity> EntityList;

// Point's has is in point.hpp
using PointEntityMap = std::unordered_map<Point, DinkyECS::Entity>;
using SortedEntities = std::vector<std::pair<int, DinkyECS::Entity>>;

struct FoundEntities {
  bool found;
  EntityList nearby;
};

class SpatialMap {
  public:
    SpatialMap() {}
    PointEntityMap table;

    void insert(Point pos, DinkyECS::Entity obj);
    void move(Point from, Point to, DinkyECS::Entity ent);
    void remove(Point pos);
    bool occupied(Point pos) const;
    DinkyECS::Entity get(Point at) const;
    FoundEntities neighbors(Point position, bool diag=false) const;

    SortedEntities distance_sorted(Point from);
    size_t size() { return table.size(); }
};
