#include "CivBaseInpBuilder.h"

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


CivBaseInpBuilder::CivBaseInpBuilder(const std::string & uri)
	:CivInpBuilder(uri)
{
	mHelper = new CivInpDbHelper(uri);
}

CivBaseInpBuilder::~CivBaseInpBuilder()
{
	delete mHelper;
}

void CivBaseInpBuilder::preHandleLikelyPipe()
{
	mHelper->handleValve();
	mHelper->handlePump();
}

void CivBaseInpBuilder::buildNode()
{
	CivNode node;
	if (!mHelper->getNode(node))
		return;

	mNewInp->setNode(node);
}

void CivBaseInpBuilder::buildPipe()
{
	ASSERT(mHelper, mNewInp);

	CivPipe pipe;
	if (!mHelper->getPipe(pipe))
		return;

	mNewInp->setPipes(pipe);
}

void CivBaseInpBuilder::buildTank()
{
	ASSERT(mHelper, mNewInp);

	CivTank tank;
	if (!mHelper->getTank(tank))
		return;

	mNewInp->setTank(tank);
}

void CivBaseInpBuilder::buildVavle()
{
	ASSERT(mHelper, mNewInp);

	CivValve valve;
	if (!mHelper->getValve(valve))
		return;

	mNewInp->setValves(valve);
}

void CivBaseInpBuilder::buildPump()
{
	ASSERT(mHelper, mNewInp);

	CivPumps valve;
	if (!mHelper->getPumps(valve))
		return;

	mNewInp->setPumps(valve);
}

void CivBaseInpBuilder::buildReservoir()
{
	ASSERT(mHelper, mNewInp);

	CivReservoirs res;
	if (!mHelper->getReservoirs(res))
		return;

	mNewInp->setReservoirs(res);
}

void CivBaseInpBuilder::buildEmitter()
{
	ASSERT(mHelper, mNewInp);

		CivEmitters emmiters;
	if (!mHelper->getEmitters(emmiters))
		return;

	mNewInp->setEmitters(emmiters);
}

void CivBaseInpBuilder::buildPatterns()
{
	ASSERT(mHelper, mNewInp);

	CivPatterns pattern;
	if (!mHelper->getPatterns(pattern))
		return;

	mNewInp->setPatterns(pattern);
}

void CivBaseInpBuilder::buildCoordnates()
{
	ASSERT(mHelper, mNewInp);

	CivCoordinates coords;
	if (!mHelper->getCoordinates(coords))
		return;

	mNewInp->setCoordnates(coords);
}

void CivBaseInpBuilder::buildVertices()
{
	return;
}

void CivBaseInpBuilder::buildLabels()
{
	ASSERT(mHelper, mNewInp);

	CivLabels labels;
	if (!mHelper->getLabels(labels))
		return;

	mNewInp->setLabels(labels);
}

void CivBaseInpBuilder::buildTags()
{
	ASSERT(mHelper, mNewInp);

	CivTags tag;
	if (!mHelper->getTags(tag))
		return;

	mNewInp->setTags(tag);
}

void CivBaseInpBuilder::buildBackDrop()
{
	return;
}

void CivBaseInpBuilder::buildQuality()
{
	ASSERT(mHelper, mNewInp);

	if (mResetToZero)
	{
		mNewInp->setQuality(mInitQuality);
		return;
	}

	CivQuality quality;
	if (!mHelper->getQuality(quality))
		return;
	
	mNewInp->setQuality(quality);
}

void CivBaseInpBuilder::buildSources()
{
	ASSERT(mHelper, mNewInp);

	CivSources sources;
	if (!mHelper->getSources(sources))
		return;

	mNewInp->setSources(sources);
}

void CivBaseInpBuilder::buildMixing()
{
	ASSERT(mHelper, mNewInp);

	CivMixing mixing;
	if (!mHelper->getMixing(mixing))
		return;

	mNewInp->setMixing(mixing);
}

void CivBaseInpBuilder::buildCurves()
{
	ASSERT(mHelper, mNewInp);

	CivCurves curves;
	if (!mHelper->getCurves(curves))
		return;

	mNewInp->setCurves(curves);
}

void CivBaseInpBuilder::buildStatus()
{
	ASSERT(mHelper, mNewInp);

	CivStatus status;
	if (!mHelper->getStatus(status))
		return;

	mNewInp->setStatus(status);
}

void CivBaseInpBuilder::buildControls()
{

}

void CivBaseInpBuilder::buildRules()
{

}

void CivBaseInpBuilder::buildDemands()
{
	ASSERT(mHelper, mNewInp);

	CivDemands mand;
	if (!mHelper->getDemands(mand))
		return;

	mNewInp->setDemands(mand);
}