/**
 * \file    Mimic_Node.cpp
 * \author  Silvan Murer
 * \date    13 October 2022
 *
 * \brief   Base class of Mimic Generic Feature implementation
 */

#include "features/Mimic_Node.hpp"
#include "Mimic_Exception.hpp"

#include "H_NodeMap.hpp."

#define GENICAM_NO_AUTO_IMPLIB
#include "GenICam.h"

#include "spdlog/spdlog.h"
#ifdef _WIN32
#include "spdlog/sinks/msvc_sink.h"
#else
#include "spdlog/sinks/stdout_color_sinks.h"
#endif

using namespace GenApi;

namespace mimic {

Mimic_Node::Mimic_Node()
{
	node = nullptr;
	type = Type_e::NODE;
}
Mimic_Node::Mimic_Node(GenApi_3_4::INode* node)
 : node(node)
{ 
	type = Type_e::NODE;
}
Mimic_Node::~Mimic_Node()
{ }

Mimic_Node::Type_e Mimic_Node::getType()
{
	return type;
}
std::string Mimic_Node::getName()
{
	if (node) {
		return std::string(node->GetName());
	}
	return "";
}

std::variant<int64_t, double, bool, std::string> Mimic_Node::getVariant(std::string name)
{
	throw Mimic_Access_Exception(std::string("Node ") + node->GetName().c_str() + " has unsupported Type! ", -660);
};
void Mimic_Node::setVariant(std::string name, std::variant<int64_t, double, bool, std::string> value)
{
	throw Mimic_Access_Exception(std::string("Node ") + node->GetName().c_str() + " has unsupported Type! ", -660);
}

bool Mimic_Node::isSelector()
{
	auto selector = dynamic_cast<ISelector*>(node);
	if (selector) {
		return selector->IsSelector();
	}
	return false;
}
std::vector<std::shared_ptr<Mimic_Node>> Mimic_Node::getSelectedFeatures()
{
	std::vector<std::shared_ptr<Mimic_Node>> gfNodeList = std::vector<std::shared_ptr<Mimic_Node>>();
	auto selector = dynamic_cast<ISelector*>(node);
	if (selector) {
		FeatureList_t featureList;
		selector->GetSelectedFeatures(featureList);
		for (auto feature : featureList) {
			gfNodeList.push_back(H_NodeMap::createGFNodePtr(feature->GetNode()));
		}
	}
	return gfNodeList;
}
std::vector<std::shared_ptr<Mimic_Node>> Mimic_Node::getSelectingFeatures()
{
	std::vector<std::shared_ptr<Mimic_Node>> gfNodeList = std::vector<std::shared_ptr<Mimic_Node>>();
	auto selector = dynamic_cast<ISelector*>(node);
	if (selector) {
		FeatureList_t featureList;
		selector->GetSelectingFeatures(featureList);
		for (auto feature : featureList) {
			gfNodeList.push_back(H_NodeMap::createGFNodePtr(feature->GetNode()));
		}
	}
	return gfNodeList;
}

} /* namespace genSDK */
