#include "CivInpBuilder.h"
#include "CivTypes.h"
#include "CivAssembly.h"


CivInpBuilder::CivInpBuilder(const std::string & uri)
	:mNewInp(new CivNewInp()), mUri(uri)
{
	mOptions.mType = "OPTIONS";
	mTimes.mType = "TIMES";
	mReactions.mType = "REACTIONS";
	mReport.mType = "REPORT";
}

CivInpBuilder::~CivInpBuilder()
{
	delete mNewInp;
}

void CivInpBuilder::setOption(const std::string& name, const std::string& val)
{
	CivParameter::ParamTable table = { name,val };
	mOptions.addItem(table);
}

void CivInpBuilder::setTimes(const std::string& name, const std::string& val)
{
	CivParameter::ParamTable table = { name,val };
	mTimes.addItem(table);
}

void CivInpBuilder::setReport(const std::string& name, const std::string& val)
{
	CivParameter::ParamTable table = { name,val };
	mReport.addItem(table);
}

void CivInpBuilder::setReaction(const std::string& name, const std::string& val)
{
	CivParameter::ParamTable table = { name,val };
	mReactions.addItem(table);
}

bool CivInpBuilder::getNewInp(std::string& infile)
{
	if (!mNewInp->writeToFile(infile))
		return false;

    return true;
}

void CivInpBuilder::buildParamter()
{
	ASSERT(mHelper, mNewInp);

	std::vector<CivParameter> parameters;
	if (!mHelper->getParameter(parameters))
		return;

	size_t total = parameters.size();
	for (int i = 0; i < total; i++)
	{
		CivParameter param = parameters[i];
		param.merge(mTimes);
		param.merge(mOptions);
		param.merge(mReactions);
		param.merge(mReport);
		mNewInp->setParamter(param, param.mType);
	}
}


void CivInpBuilder::setQuality(const std::string& name, const std::string& val)
{
	mInitQuality.addItem({ name ,val });
}

void CivInpBuilder::setQualityType(CivInpHelperAbs::QualityType type)
{
	mHelper->setQualityType(type);
}

void CivInpBuilder::buildCurves()
{
}

void CivInpBuilder::buildTags()
{

}

void CivInpBuilder::buildBackDrop()
{

}

void CivInpBuilder::buildLabels()
{

}

void CivInpBuilder::buildVertices()
{

}

void CivInpBuilder::setPatternTime(const std::string& patternTime)
{ 
	mHelper->setPatternTime(patternTime);
}

void CivInpBuilder::isDelayTimeSmuli(bool isDelay)
{
	mHelper->isDelayTimeSimul(isDelay);
}