/**
* @brief
json构造器类

* @version
  V 1.0.0

* @author

* @date
  创建时间:  2018-08-17\n

* @note
  2018-08-17  创建类。\n

* @warning

* @bug
  
*/

#ifndef _JSONBUILDER_H_
#define _JSONBUILDER_H_
#include <map>
#include <rapidjson/document.h>
#include "jsonCommon.h"
#include "ws_common.h"

namespace sys
{
	class jsonBuilder
	{
	private:
		/**
		* @brief
		加上版本信息函数。

		* @param  [out] rapidjson::Value& root  根jason对象\n
		* @param  [out] rapidjson::Document::AllocatorType& Allocator  分配器\n

		* @return 无\n

		* @note

		* @warning

		* @bug

		*/
        void __AddVersion( rapidjson::Value& root, rapidjson::Document::AllocatorType& Allocator );
		/**
		* @brief
		设置命令信息函数。

		* @param  [in] const char* szCmd  命令\n
		* @param  [out] rapidjson::Value& root  根jason对象\n
		* @param  [out] rapidjson::Document::AllocatorType& Allocator  分配器\n

		* @return 无\n

		* @note

		* @warning

		* @bug

		*/
		void __SetCmd( const char* szCmd, rapidjson::Value& root, rapidjson::Document::AllocatorType& Allocator );
		/**
		* @brief
		构造卡明细函数。

		* @param  [in] const _CARD_POS_& CardPos  卡位置\n
		* @param  [out] rapidjson::Document::AllocatorType& Allocator  分配器\n
		* @param  [out] rapidjson::Value& DetailItem  生成的单个人卡明细\n

		* @return 构造是否成功\n

		* @note

		* @warning

		* @bug

		*/
		bool __BuildDetail( const _CARD_POS_& CardPos, rapidjson::Document::AllocatorType& Allocator, rapidjson::Value& DetailItem );
		/**
		* @brief
		构造部门列表json对象函数。

		* @param  [in] const std::map<int, _STAT_DEPT_ITEM_>& dept_map  部门统计列表\n
		* @param  [out] rapidjson::Document::AllocatorType& Allocator  分配器\n
		* @param  [out] rapidjson::Value& Dept  生成的部门json对象\n

		* @return 构造是否成功\n

		* @note

		* @warning

		* @bug

		*/
		bool __BuildDept( const std::map<int, _STAT_DEPT_ITEM_>& dept_map, rapidjson::Document::AllocatorType& Allocator, rapidjson::Value& Dept );
		/**
		* @brief
		构造部门项json对象函数。

		* @param  [in] const _STAT_DEPT_ITEM_& st_dept_item  部门项\n
		* @param  [out] rapidjson::Document::AllocatorType& Allocator  分配器\n
		* @param  [out] rapidjson::Value& DeptItem  生成的部门项json对象\n

		* @return 无\n

		* @note

		* @warning

		* @bug

		*/
		void __BuildDeptItem( const _STAT_DEPT_ITEM_& st_dept_item, rapidjson::Document::AllocatorType& Allocator, rapidjson::Value& DeptItem );
		/**
		* @brief
		构造基础卡项json对象函数。

		* @param  [in] const _BASE_CARD_& Card  基础卡对象\n
		* @param  [out] rapidjson::Document::AllocatorType& Allocator  分配器\n
		* @param  [out] rapidjson::Value& CardItem  生成的卡json对象\n

		* @return 无\n

		* @note

		* @warning

		* @bug

		*/
		void __BuildBaseCardItem( const _BASE_CARD_& Card, rapidjson::Document::AllocatorType& Allocator, rapidjson::Value& CardItem );
		/**
		* @brief
		生成Dept Map函数。

		* @param  [in] const _CARD_POS_& CardPos  卡定位数据\n
		* @param  [out] std::map<int, _STAT_DEPT_ITEM_>& DeptMap  生成的Dept Map\n

		* @return 无\n

		* @note

		* @warning

		* @bug

		*/
		void __CreateDeptMap( const _CARD_POS_& CardPos, std::map<int, _STAT_DEPT_ITEM_>& DeptMap );
		/**
		* @brief
		生成_STAT_DEPT_ITEM_结构体函数。

		* @param  [in] const _CARD_POS_& CardPos  卡定位数据\n
		* @param  [out] _STAT_DEPT_ITEM_& DeptItem  生成的DeptItem\n

		* @return 无\n

		* @note

		* @warning

		* @bug

		*/
		void __CreateDeptItem( const _CARD_POS_& CardPos, _STAT_DEPT_ITEM_& DeptItem );
		/**
		* @brief
		构造id sum map对象函数。

		* @param  [in] const std::map<int,int>& id_sum_map  id sum 列表\n
		* @param  [in] const char* szName  名称\n
		* @param  [out] rapidjson::Document::AllocatorType& Allocator  分配器\n
		* @param  [out] rapidjson::Value& Dept  生成的部门json对象\n

		* @return 无\n

		* @note

		* @warning

		* @bug

		*/
		void __BuildIDSumMap( const std::map<int,int>& id_sum_map, const char* szName, rapidjson::Document::AllocatorType & Allocator, rapidjson::Value & Parent );
		/**
		* @brief
		格式化生成卡号函数。

		* @param  [in] const _BASE_CARD_& CardPos  卡位置\n

		* @return 格式化生成的卡号\n

		* @note

		* @warning

		* @bug

		*/
        std::string __FmtCardID( const _BASE_CARD_& CardPos );
	public:
		jsonBuilder();
		virtual ~jsonBuilder();
		/**
		* @brief
		生成登录jason函数。

		* @param  [in] const _JS_LOGIN_& Login  登录参数\n

		* @return 如果成功返回生成的json字符串,否则返回空字符串\n

		* @note

		* @warning

		* @bug

		*/
		std::string BuildLogin( const _JS_LOGIN_& Login );
		/**
		* @brief
		生成卡位置jason函数。

		* @param  [in] const std::map<int, _CARD_POS_>& CardPosList  卡位置列表\n

		* @return 如果成功返回生成的json字符串,否则返回空字符串\n

		* @note

		* @warning

		* @bug

		*/
		std::string BuildCardPos( const std::map<uint64_t, _CARD_POS_>& CardPosList );
        std::string build_ios_card_pos(const _CARD_POS_& card);
        std::string build_tmp_card_pos(const std::map<uint64_t, _CARD_POS_>& cards);
        std::string build_traffic_light(const std::vector<light_state> lights);
		std::string build_device_state(const std::vector<device_state> vtd);
		std::string build_load_history_completed();
		/**
		* @brief
		生成车辆进入特殊区域jason函数。

		* @param  [in] const _BASE_CARD_& Card  卡结构体\n

		* @return 如果成功返回生成的json字符串,否则返回空字符串\n

		* @note

		* @warning

		* @bug

		*/
		std::string BuildSpecialAreaProcess( const _BASE_CARD_& stCard );
		/**
		* @brief
		解析呼叫结构体函数。

		* @param  [in] const _JS_LOGIN_& Login  登录参数\n

		* @return 如果成功返回生成的jason字符串,否则返回空字符串\n

		* @note

		* @warning

		* @bug

		*/
		bool ParseCall_Card_Req( const std::string& JasonText, _JS_CALL_CARD_REQ_& CallCardReq, std::string& Error );
	};
}

#endif /* _JSONBUILDER_H_ */