#include "ModuleMerge.h"
#include <boost/algorithm/string.hpp>

namespace mdd {
	ModuleMerge::ModuleMerge() {
		std::vector<double> default_val = { 1 };
		addInput("Value", default_val);
		addInput("Value", default_val);
		addOutput("Value", default_val);
		setType("Merge");
	}

	int ModuleMerge::addModuleInput() {
		std::vector<double> default_val = { 1 };
		return addInput("Value", default_val);
	}

	int ModuleMerge::removeModuleInput() {
		return pop_backInput();
	}

	std::string ModuleMerge::setInputType(const std::string& input_id, const std::string& new_type) {
		for (int id = 0; id < getInputs().size(); ++id) {
			if (getInput(id)->getID() == input_id) {
				getInput(id)->setType(new_type);
				return getInput(id)->getID();
			}
		}
		return "";
	}
	state ModuleMerge::update() {
		std::vector<double>  ret;
		for (size_t i = 0; i < getInputs().size(); i++)
		{
			std::string key = getInput(i)->getType();
			boost::algorithm::to_lower(key);
			for (size_t j = 0; j < getInput(i)->getValue().size(); j++)
			{
				ret.push_back(getInput(i)->getValue()[j]);
			}
		}
		return getOutput(0)->setValue(ret);
	}
}
