#include "ormConfigurator.h"

ormNode::ormNode() {}

void ormNode::setParams(const nlohmann::json &msg, const std::string &url) {
    std::string endpoint = getEndpointFromUrl(url);
    if (endpoint == "SC_SD_F1") {
        this->_params.orm_peer = msg.value("orm_peer", "");
        this->_params.orm_version = msg.value("orm_version", "");
        this->_params.orm_opc_client_peer = msg.value("orm_opc_client_peer", "");
        this->_params.init_status = msg.value("status", "");
    } else if (endpoint == "SC_SD_F2") {
        this->_params.location_status = msg.value("status", "");

        if (this->_params.location_status == "init_OK_LOCATION") {
            {
                std::lock_guard<std::mutex> lock(this->status_mutex);
                this->status_ready = true;
            }
            this->status_cv.notify_one();
        }
    } else if (endpoint == "SC_SD_F3") {
        this->_params.chain_status = msg.value("status", "");
    }
}

std::string getEndpointFromUrl(std::string url){
    size_t pos = url.find_last_of('/');
    std::string endpoint;
    if (pos != std::string::npos) {
        endpoint = url.substr(pos + 1);
    }
    return endpoint;
}