#pragma once

#include <nlohmann/json.hpp>

#include <mutex>
#include <optional>
#include <string>

namespace lm {

class Database;

class PathGuideStore
{
public:
  explicit PathGuideStore(Database& db);

  nlohmann::json list(const std::string& site_id = "") const;
  std::optional<nlohmann::json> find(const std::string& id) const;
  std::optional<nlohmann::json> create(const nlohmann::json& payload, std::string& err);
  bool update(const std::string& id, const nlohmann::json& payload, std::string& err);
  bool remove(const std::string& id, std::string& err);

private:
  Database& db_;
  mutable std::mutex mu_;

  bool findNameConflictUnlocked(const std::string& site_id,
                                const std::string& name,
                                const std::string& except_id) const;
};

}  // namespace lm
