#pragma once

#include <nlohmann/json.hpp>

#include <string>

namespace lm {

class Database;
class IoModuleService;
class MapStore;

class IoZoneRuntime
{
public:
  void onRobotAtPosition(Database& db,
                         MapStore& maps,
                         IoModuleService& io,
                         const std::string& map_id,
                         const std::string& position_id,
                         nlohmann::json& log);

private:
  std::string last_zone_key_;

  static bool pointInPolygon(double x, double y, const nlohmann::json& points);
  static bool zoneContainsPoint(const nlohmann::json& zone, double x, double y);
  static std::optional<std::pair<double, double>> positionCoords(const nlohmann::json& map,
                                                                 const std::string& position_id);
};

}  // namespace lm
