#include <softbus_edge/config/EdgeConfig.h>

#include <fstream>
#include <nlohmann/json.hpp>

namespace softbus::edge {

bool EdgeConfig::loadFromFile(const std::string& path)
{
    std::ifstream ifs(path);
    if (!ifs) {
        return false;
    }
    nlohmann::json j;
    ifs >> j;
    if (!j.contains("edge")) {
        return false;
    }
    const auto& edge = j["edge"];
    deviceId = edge.value("deviceId", deviceId);
    daemonHost = edge.value("daemonHost", daemonHost);
    daemonPort = static_cast<uint16_t>(edge.value("daemonPort", static_cast<int>(daemonPort)));
    heartbeatPeriodMs = edge.value("heartbeatPeriodMs", heartbeatPeriodMs);
    pointTablePath = edge.value("pointTable", pointTablePath);
    return true;
}

} // namespace softbus::edge
