#include "CivInpConvertor.h"
#include "CivProjInpBuilder.h"
#include "CivInpDirector.h"
#include "CivBaseInpBuilder.h"
#include "CivCommonUtils.h"

CivInpConvertor::CivInpConvertor(const std::string& uri)
	:mUri(uri)
{

}

CivInpConvertor::~CivInpConvertor()
{

}

std::string CivInpConvertor::convertPorjInp(
	const std::string& projCode,
	const std::string& start)
{
	CivProjInpBuilder* builder = new CivProjInpBuilder(mUri);
	builder->setProjCode(projCode);
	builder->setTimes("Duration", "0");
	builder->setTimes("Start Clocktime", start);

	CivInpDirector director;
	director.setBuilder(builder);
	director.create();

	std::string inpFile = CivCommonUtils::getExePath() + "\\test.inp";
	if (builder->getNewInp(inpFile))
	{
		delete builder;
		return NULL;
	}
	
	delete builder;
	return inpFile;
}

std::string CivInpConvertor::convertBaseInp()
{
	CivInpBuilder* builder = new CivBaseInpBuilder(mUri);
	CivInpDirector director;
	director.setBuilder(builder);
	director.create();

	std::string inpFile = CivCommonUtils::getExePath() + "\\test.inp";
	if (!builder->getNewInp(inpFile))
	{
		delete builder;
		return NULL;
	}

	delete builder;
	return inpFile;
}

std::string CivInpConvertor::convertTrackInp(const std::string& sn,
	const std::string& hours)
{
	CivInpBuilder* builder = new CivBaseInpBuilder(mUri);
	builder->setOption("Quality Tracking", sn);
	builder->setTimes("Duration", hours);
	builder->resetAllToZero();
	builder->setQuality(sn, "1");

	CivInpDirector director;
	director.setBuilder(builder);
	director.create();

	std::string inpFile = CivCommonUtils::getExePath() + "\\test.inp";
	if (builder->getNewInp(inpFile))
	{
		delete builder;
		return NULL;
	}

	delete builder;
	return inpFile;
}