#include "jfxmap_python.h"
#include "MapInterface.hpp"
#include <memory>

jf::MapInterface g_jfMap;
static int g_isInit = 0;
MapInfo g_info;

int add(int i, int j)
{
    return i + j;
}

bool InitMap(std::string strPrjPath, std::string strCfgPath)
{
	printf("strPrjPath = %s, strCfgPath = %s g_isInit = %d", strPrjPath.c_str(), strCfgPath.c_str(), g_isInit);
	//if (g_jfMap == nullptr)
	//{
	//	g_jfMap = new jf::MapInterface();
	//	//g_jfMap->Init(strPrjPath, strCfgPath);
	//	return true;
	//}
	if (g_isInit == 0)
	{
		g_jfMap.Init(strPrjPath, strCfgPath);
		g_isInit = 1;
		return true;
	}
	return false;
}
MapInfo* GetMapData(double lat, double lon, double carAngle)
{
	memset(&g_info, 0, sizeof(g_info));
	if (g_isInit == 1)
	{
		const jf::Point ptInLoc = { lon, lat, 0.0 };
		long lOutRaodId;
		std::vector<long> vctlOutPreRoadId;
		std::vector<long> vctlOutNxtRoadId;
		int nLaneCnt;
		int nOutLaneNum;
		jf::LaneType nOutLaneType;
		jf::EdgeCrossType nOutLeftEdgeCrossType;
		jf::EdgeCrossType nOutRightEdgeCrossType;
		int nOutSpeedLimit;
		double dOutLaneAngle;
		jf::Point ptOutFoot;
		if (g_jfMap.GetMapData(ptInLoc, carAngle, lOutRaodId, vctlOutPreRoadId, vctlOutNxtRoadId, nLaneCnt, nOutLaneNum, nOutLaneType, nOutLeftEdgeCrossType, nOutRightEdgeCrossType, nOutSpeedLimit, dOutLaneAngle, ptOutFoot))
		{
			g_info.isInMap = 1;
			g_info.lOutRaodId = lOutRaodId;
			g_info.vctlOutPreRoadId = vctlOutPreRoadId;
			g_info.vctlOutNxtRoadId = vctlOutNxtRoadId;
			g_info.nLaneCnt = nLaneCnt;
			g_info.nOutLaneNum = nOutLaneNum;
			g_info.nOutLaneType = static_cast<int>(nOutLaneType);
			g_info.nOutLeftEdgeCrossType = static_cast<int>(nOutLeftEdgeCrossType);
			g_info.nOutRightEdgeCrossType = static_cast<int>(nOutRightEdgeCrossType);
			g_info.nOutSpeedLimit = nOutSpeedLimit;
			g_info.dOutLaneAngle = dOutLaneAngle;
			g_info.ptOutFoot_lat = ptOutFoot.dLat;
			g_info.ptOutFoot_lon = ptOutFoot.dLon;
		}
	}
	return &g_info;
}
