#ifndef CIVTABLETEMP_H
#define CIVTABLETEMP_H

#include<string>
#include<vector>
#include<map>

#include "CivTypes.h"

struct FieldProperty
{
	std::string mFiledName; //字段名
	std::string mFieldType; // 字段类型
};

#define FiledPropertys std::vector<FieldProperty>
class CivDbConn;
/**
*  数据库表模板
*/
class CivTableTemp
{
public:
	// 字段类型
	enum FieldType {
		FILED_INT,
		FILED_INTEGER,
		FILED_DOUBLE,
		FILED_VARCHAR,
		FILED_VARCHAR64,
		FILED_VARCHAR128,
		FILED_VARCHAR256,
		FILED_DATETIME,
		FILED_JSON,
		FILED_DATE
	};

	explicit CivTableTemp();

	~CivTableTemp();

	// 返回创建表的sql语句
	Str createSql();
	/*
	 * @brief 表名
	*/
	Str name() const { return mTableName; }

	void setName(StrQuote name) { mTableName = name; }

	/**
	*@brief 添加字段属性
	*@fileName：字段名
	*@filedType：字段类型
	*/
	void addProperty(std::string fileName, FieldType filedType);

	/**
	*@brief 数据库创建模板表
	*@dbConn: 数据库连接对象
	*/
	bool updateToDb(CivDbConn* dbConn);

protected:
	Str mTableName;  // 表名

	FiledPropertys mPropertys; // 字段和字段属性
	std::map< FieldType, Str> mFieldTyepMap;
};

/**
 节点表模板
*/
class CivJunctionTableTemp :public CivTableTemp
{
public:
	// 字段名
	typedef struct TableFileds
	{
		Str ID = "id";
		Str geom = "geom";
		Str thePoint = "本点号";
		Str xCoord = "横坐标";
		Str yCoord = "纵坐标";
		Str elev = "高程";
		Str demand = "需水量";
		Str pattern = "需水量模式";
		Str head = "总水头";
		Str freeHead = "自由水头";
		Str actualDemand = "实际需水量";
		Str code = "code";
		Str createUser = "create_user";
		Str modifyUser = "modify_user";
		Str createTime = "create_time";
		Str  modifyTime = "modify_time";
		Str symbolAngle = "symbol_angle";
		Str compType = "组分类型";
		Str pressure = "压力";
		Str quality = "水质";
		Str initQuality = "初始水质";
	}JunctionTable;

	explicit CivJunctionTableTemp(Str tableName);

};

/**
    管线表模板
*/
class CivPipeTableTemp :public CivTableTemp
{
public:
	// 字段名
	typedef struct TableFileds
	{
		Str ID = "id";
		Str geom = "geom";
		Str snNo = "编号";
		Str thePoint = "本点号";
		Str lastPoint = "上点号";
		Str length = "管长";
		Str material = "管材";
		Str diameter = "管径";
		Str friction = "摩阻系数";
		Str localLoss = "局部损失系";
		Str initStatus = "初始状态";
		Str buryingTime = "埋设时间";
		Str flow = "流量";
		Str velocity = "流速";
		Str unitHeadLoss = "单位水头损";
		Str headLoss = "水头总损失";
		Str unitPressLoss = "单位压力损";
		Str pressLoss = "压力总损失";
		Str lastHead = "上点水头";
		Str theHead = "本点水头";
		Str lastPress = "上点压力";
		Str thePress = "本点压力";
		Str localHeadLoss = "局部水头损";
		Str fracHeadLoss = "摩擦水头损";
		Str status = "状态";
		Str guid = "guid";
		Str code = "code";
		Str fromCode = "from_code";
		Str fromLayer = "from_layer";
		Str toCode = "to_code";
		Str toLayer = "to_layer";
		Str createUser = "create_user";
		Str modifyUser = "modify_user";
		Str createTime = "create_time";
		Str modifyTime = "modify_time";
		Str remarks = "备注";
		Str quality = "水质";
	}PipeTable;
	explicit CivPipeTableTemp();
};

/**
水泵
*/
class CivPumpTableTemp :public CivTableTemp
{
public:
	typedef struct TableFileds
	{
		Str ID = "id";
		Str geom = "geom";
		Str thePoint = "本点号";
		Str xCoord = "横坐标";
		Str yCoord = "纵坐标";
		Str startPoint = "起始节点";
		Str endPoint = "终止节点";
		Str curve = "水泵曲线";
		Str ratio = "转速比";
		Str flow = "流量";
		Str headCurve = "扬程曲线";
		Str status = "状态";
		Str code = "code";
		Str createUser = "create_user";
		Str modifyUser = "modify_user";
		Str createTime = "create_time";
		Str modifyTime = "modify_time";
		Str SymbolAngle = "symbol_angle";
		Str compType = "组分类型";
		Str power = "功率";
	 } PumpTable;
	explicit CivPumpTableTemp();
};

/**
   水池
*/
class CivTankTableTemp :public CivTableTemp
{
public:
	typedef struct TableFileds
	{
		Str ID = "id";
		Str geom = "geom";
		Str thePoint = "本点号";
		Str xCoord = "横坐标";
		Str yCoord = "纵坐标";
		Str elev = "高程";
		Str diametor = "直径";
		Str baseLevel = "基础水位";
		Str initLevel= "初始水位";
		Str highLevel = "最高水位";
		Str lowLevel = "最低水位";
		Str flowIn = "输入流量";
		Str flowOut = "输出流量";
		Str leveHeight = "液位高度";
		Str capacity = "容量";
		Str volCurve = "容积曲线";
		Str percentage = "装满水池百";
		Str status = "状态";
		Str code = "code";
		Str createUser = "create_user";
		Str modifyUser = "modify_user";
		Str createTime = "create_time";
		Str modifyTime = "modify_time";
		Str SymbolAngle = "symbol_angle";
		Str compType = "组分类型";
	}TankTable;
	explicit CivTankTableTemp();
};

/**
  水库
*/
class CivResourcesTableTemp :public CivTableTemp
{
public:
	typedef struct TableFileds
	{
		Str ID = "id";
		Str geom = "geom";
		Str thePoint = "本点号";
		Str xCoord = "横坐标";
		Str yCoord = "纵坐标";
		Str headPattern = "水头模式曲";
		Str elev = "高程";
		Str head = "水头";
		Str flow = "流出流量";
		Str code = "code";
		Str createUser = "create_user";
		Str modifyUser = "modify_user";
		Str createTime = "create_time";
		Str modifyTime = "modify_time";
		Str SymbolAngle = "symbol_angle";
		Str compType = "组分类型";
	}ResourcesTable;
	explicit CivResourcesTableTemp();
};

/**
阀门
*/
class CivValveTableTemp :public CivTableTemp
{
public:
	typedef struct TableFileds
	{
		Str id = "本点号";
		Str geom = "geom";
		Str xCoord = "横坐标";
		Str yCoord = "纵坐标";
		Str startPoint = "起始节点";
		Str endPoint = "终止节点";
		Str diameter = "直径";
		Str status = "状态";
		Str type = "阀门类型";
		Str setting = "阀门设置";
		Str loss = "损失系数";
		Str flow = "流量 ";
		Str veclocity = "流速";
		Str headLoss = "水头损失";
		Str code= "code";
		Str createUser= "create_user"	;
		Str modityUser = "modify_user";
		Str createTime= "create_time";
		Str modifyTime = "modify_time"  ;
		Str symbolAngle= "symbol_angle";
		Str compType = "组分类型";
	}ValveTable;
	explicit CivValveTableTemp();
};

/**
   节点模拟结果存储表
*/
class CivNodeResultTableTemp :public CivTableTemp
{
public:
	typedef struct TableField
	{
		Str Number = "本点号";
		Str dHead = "水头";
		Str dPressure = "压力";
		Str dElevation = "标高";
		Str dDemand = "实际需水量";
		Str dTankVolume = "水池容量";
		Str dTankMaxVolume = "水池最大容量";
		Str dTankLevel = "液位高度";
		Str dQuality = "水质";
		Str dDate = "日期";
		Str dInterval = "时段";
		Str dModifyTime = "修改时间";
	} NodeResultTable;
	explicit CivNodeResultTableTemp();
};
/**
	模拟结果线表
*/
class CivPipeResultTableTemp :public CivTableTemp
{
public:
	typedef struct TableField
	{
		Str szNo = "编号";
		Str dFlow = "流量";
		Str nFlowDirect = "流向";
		Str dVelocity = "流速";
		Str dHeadloss = "水头损失";
		Str dUnitHeadloss = "单位水头损";
		Str dFromNodHeadloss = "上点水头";
		Str dToNodHeadloss = "本点水头";
		Str dLocalHeadloss = "局部水头损";
		Str dFrictionHeadloss = "摩擦水头损";
		Str szStatus = "状态";
		Str dQuality = "水质";
		Str dDate = "日期";
		Str dInterval = "时段";
		Str dModifyTime = "修改时间";
	}PipeResultTable;
	explicit CivPipeResultTableTemp();
};

/**
	 模式表
*/
class CivPatternTableTemp :public CivTableTemp
{
public:
	typedef struct TableField
	{
		Str modelName = "model_name";
		Str modelType = "model_type";
		Str modelData = "model_data";
	} PatternTable;

	enum PatternType
	{
		PATTERN_DEMAND,// 需水量模式
		PATTERN_PRESS// 压力模式
	};
	explicit CivPatternTableTemp();
};

/**
	参数表
*/
class CivParametorTableTemp :public CivTableTemp
{
public:
	typedef struct TableField
	{
		Str name = "参数名";
		Str val = "参数值";
		Str type = "参数类型";
		Str netName = "管网名";
	}ParametorTable;
	explicit CivParametorTableTemp();
};

/**
   曲线表
*/
class CivCurveTableTemp :public CivTableTemp
{
public:
	typedef struct TableField
	{
		Str CurveName = "curve_name";
		Str CurveType = "curve_type";
		Str CurveData = "curve_data";
	}CurveTable;

	// 曲线类型
	enum CurveType
	{
		CURVE_ELEV,// 水泵扬程与流量
		CURVE_EFFIC,//水泵效率与流量
		CURVE_VOLUME,// 水池容积与水深
		CURVE_HEADLOSS //常规阀门的水头损失与流量
	};
	explicit CivCurveTableTemp();
};

#endif // !CIVTABLETEMP_H



