#pragma once
#include "CivAssembly.h"
#include "pandaDbManager.h"

class CivConnection;

/**
   转inp操作数据库类
*/
class PANDADBMANAGER_API CivInpHelperAbs
{
public:
	// 水质模拟时间
	enum QualityType
	{
		Age, // 水龄
		Chlorine // 余氯
	};

	explicit CivInpHelperAbs(const std::string& uri);
	virtual ~CivInpHelperAbs();

	virtual void handlePump() = 0;
	virtual void handleValve() = 0;
	// 组件需要重载
	virtual bool getNode(CivNode& node)=0 ;
	virtual bool getPipe(CivPipe& pipe)=0 ;
	virtual bool getTank(CivTank& tank) = 0;
	virtual bool getValve(CivValve& valve) =0;
	virtual bool getPumps(CivPumps& pump) =0;
	virtual bool getReservoirs(CivReservoirs& reservoirs) =0;
	
	virtual bool getCoordinates(CivCoordinates& coord) =0;	
	virtual bool getQuality(CivQuality& quality)=0;
	virtual bool getStatus(CivStatus& status) = 0;

	void getSnToCode(std::map<std::string, std::string>& coord);

	// 不要重载函数
	void setPatternTime(std::string time); // 解析模式时刻
	void convertPatterns();
	void isDelayTimeSimul(bool isDelay);

	bool getPatterns(CivPatterns& patterns) ;
	bool getCurves(CivCurves& curves) ;
	bool getDemands(CivDemands& demands) ;
	bool getSources(CivSources& sources) ;
	bool getLabels(CivLabels& labels) ;
	bool getTags(CivTags& tags) ;
	bool getMixing(CivMixing& mixing);
	bool getParameter(std::vector<CivParameter>& param);
	bool getEmitters(CivEmitters& emitter);
	void setQualityType(QualityType qualiType);
protected:
	QualityType mQualityType;
	CivConnection* mDbConn;

	bool isDelayTime; // 是否做延时模拟
	int mPatternTime;  // 模式
	std::map<std::string,std::vector<std::string>> mPatterns; // 需水量模式乘子

	void handleDelayPattern(const std::string& sourceDemand, const std::string& patternID, std::string& demand, std::string& pattern);
	std::string mCondtion;

	std::vector<CivPipe::PipesTable> mPipesVec;  // 
	std::vector<CivNode::NodeTable> mNodeVec; // 处理与阀门相连的管段
	std::vector<CivValve::ValveTable> mValuvesVec; // 阀门
	std::vector<CivStatus::StatusTable> mStatusVec; // 状态组件
	std::vector<CivPumps::PumpTable> mPumpTables;  // 水泵
	std::vector<CivCoordinates::CoordTable> mCoords;
};
