#include "GnsNode.hpp"
#include "GnsPort.hpp"
#include "GnsProject.hpp"

#include <cpr/cpr.h>
#include <vector>


namespace gns {


GnsNode::GnsNode(const GnsProject *project, std::string uuid, const std::vector<GnsPort>& ports) {
    this->project = project;
    this->uuid = std::move(uuid);
    this->ports = ports;
}

std::string GnsNode::getApiBase() const {
    return this->project->getApiBase() + "nodes/" + this->uuid + "/";
}

std::string GnsNode::getUuid() const {
    return this->uuid;
}

std::vector<GnsPort> GnsNode::getPorts() const {
    return this->ports;
}

void GnsNode::start() const {
    // request the API endpoint
    cpr::Url endpoint = this->getApiBase() + "start";
    cpr::Response response = Post(endpoint);

    // check for a valid response
    if (response.error.code != cpr::ErrorCode::OK)
        throw std::runtime_error(response.error.message);
}


}