#pragma once
#include <vector>
#include <map>
#include <string>
#include "jidu_macro.h"
#include "cJSON.h"


using namespace std;

class CVehicleConfig
{
public:
	CVehicleConfig();
	static CVehicleConfig* getInstance();
	
	uint64_t  GetFlashFileSize(int ecuId, string ecuName, string ecuHwpn, string ecuSwpn);
	bool GetFlashFileInfo(int ecuId, string ecuName, string ecuHwpn, string ecuSwpn, JD_VSP_FLASH_CONFIG_t& oneFlashInfo);
	bool setCurrentVehicleSoftVer(const std::string& strVehicleSoftVer);
	bool setCurrentVehicleSoftVer(const std::string& strVehicleType, const std::string& strVehicleSoftVer);
	bool getEcuFileInfo(string ecuName, string ecuHwpn, vector<JD_VSP_FLASH_CONFIG_t>& vecFlash);
	bool getEcuFileInfo(uint16_t ecuId, string ecuHwpn, vector<JD_VSP_FLASH_CONFIG_t>& vecFlash);
	bool getEcuConfig(string ecuName, JD_ECU_CONFIG_t& ecuConfig);
	bool getEcuConfig(uint16_t ecuId, JD_ECU_CONFIG_t& ecuConfig);

	void setCurrentVehicleType(string vehicleType);
	string getCurrentVehicleType(void);
	string getCurrentVehicleSoftVer(void);
	string getDiagnosisDir();
	string getDiagnosisEcuFilesDir();

public:
	map<string, vector<string>> m_mapVehicleType;//<车型,车辆版本>
	bool reloadLoacalPkg();
	bool reloadConfig();
	bool reorder(); //重新排序
	bool IsCompleted(const std::string vehicleType, const std::string vehicleSoftVer);
	bool IsCompleted(uint16_t bridgeId);
	bool IsLatestBatch(const std::string vehicleType, const std::string vehicleSoftVer);

public:
	static CVehicleConfig* instance;
	static std::string m_strVehicleSoftVer;
	static std::string m_strVehicleType;

	static vector<std::string> m_vecVehicleSoftVer; 
	static JD_VEHICLE_CONFIG_t m_vehicleConfig; //整车包信息

	string DiagnosisDir;
	string DiagnosisEcuFilesDir;
	string DiagnosisBridgeEcuFilesDir;

	string getEcuName_byOrderEcuName(string orderName);
	bool GetList(cJSON* obj, vector<std::string>& vecList);
	bool GetEcuList(cJSON* ecuList, vector<JD_ECU_CONFIG_t>& vecListEcu);
	bool GetOderList(cJSON* oderList, vector<JD_VSP_FLASH_INFO_t>& vecList);
	bool GetOtherEcuHWCheck(cJSON* otherEcuHWCheck, vector<JD_FLASH_PRECONDITION>& vecPreconditionList);

	string getVehicleTypeFileDir();
	string getPkgFileDir();
	string getFlashFileDir();
	string getCertFilepath();
	uint16_t getEcuId(uint16_t ecuId, string ecuHwpn);

	static uint16_t m_bridgeId;
	string getBridgeFileDir(int bridgeId);
	bool getBridgeFlashFileInfo(int bridgeId, string ecuName, string hwpn, string swpn, JD_VSP_FLASH_CONFIG_t& oneFlashInfo);
	bool getBridgeEcuFileInfo(int bridgeId, string hwpn, vector<JD_VSP_FLASH_CONFIG_t>& vecFlash);
	string getBridgeEcuName(int bridgeId);
	uint16_t getBridgeEcuId(int bridgeId);
};

