#include "CivProjInpBuilder.h"
#include "CivProjInpDbHelper.h"

CivProjInpBuilder::CivProjInpBuilder(const std::string& uri)
	:CivInpBuilder(uri)
{
	mHelper = new CivProjInpDbHelper(uri);
}

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

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

	mNewInp->setNode(node);
}

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

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

	mNewInp->setPipes(pipe);
}

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

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

	mNewInp->setTank(tank);
}

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

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

	mNewInp->setValves(valve);
}

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

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

	mNewInp->setPumps(valve);
}

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

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

	mNewInp->setReservoirs(res);
}

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

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

	mNewInp->setEmitters(emmiters);
}

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

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

	mNewInp->setPatterns(pattern);
}

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

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

	mNewInp->setCoordnates(coords);
}

void CivProjInpBuilder::buildVertices()
{
	return;
}

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

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

	mNewInp->setLabels(labels);
}

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

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

	mNewInp->setTags(tag);
}

void CivProjInpBuilder::buildBackDrop()
{
	return;
}

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

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

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

	mNewInp->setQuality(quality);
}

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

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

	mNewInp->setSources(sources);
}

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

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

	mNewInp->setMixing(mixing);
}

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

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

	mNewInp->setCurves(curves);
}

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

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

	mNewInp->setStatus(status);
}

void CivProjInpBuilder::buildControls()
{

}

void CivProjInpBuilder::buildRules()
{

}

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

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

	mNewInp->setDemands(mand);
}

void CivProjInpBuilder::setProjCode(const std::string& projCode)
{
	mProjCode = projCode;
	CivProjInpDbHelper* helper = static_cast<CivProjInpDbHelper*>(mHelper);
	if (helper != nullptr)
		helper->setProjCode(projCode);
}

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