#include<iostream>
#include<cstdlib>



#include "nlsr.hpp"
#include "nlsr_dm.hpp"
#include "nlsr_tokenizer.hpp"
#include "nlsr_lsdb.hpp"

using namespace std;
using namespace ndn;

void
DataManager::processContent(nlsr& pnlsr, const ndn::Interest &interest,
								               const ndn::Data & data)
{

	cout << "I: " << interest.toUri() << endl;

	string dataName(data.getName().toUri());
	string dataContent((char *)data.getContent().value());
	
  	cout << "D: " << dataName << endl;
	cout << "Data Content: " << dataContent << endl;

	nlsrTokenizer nt(dataName,"/");
	string chkString("info");
	if( nt.doesTokenExist(chkString) ){
		processContentInfo(pnlsr,dataName,dataContent);
	}

}

void
DataManager::processContentInfo(nlsr& pnlsr, string& dataName,
                                                           string& dataContent)
{
	nlsrTokenizer nt(dataName,"/");
	string chkString("info");
	string neighbor="/" + nt.getFirstToken()
							+nt.getTokenString(0,nt.getTokenPosition(chkString)-1);
	int oldStatus=pnlsr.getAdl().getStatusOfNeighbor(neighbor);
	int infoIntTimedOutCount=pnlsr.getAdl().getTimedOutInterestCount(neighbor);
	//debugging purpose start
	cout <<"Before Updates: " <<endl;
	cout <<"Neighbor : "<<neighbor<<endl;
	cout<<"Status: "<< oldStatus << endl;
	cout<<"Info Interest Timed out: "<< infoIntTimedOutCount <<endl;
	//debugging purpose end

	pnlsr.getAdl().setStatusOfNeighbor(neighbor,1);
	pnlsr.getAdl().setTimedOutInterestCount(neighbor,0);

	int newStatus=pnlsr.getAdl().getStatusOfNeighbor(neighbor);
	infoIntTimedOutCount=pnlsr.getAdl().getTimedOutInterestCount(neighbor);

	//debugging purpose
	cout <<"After Updates: " <<endl;
	cout <<"Neighbor : "<<neighbor<<endl;
	cout<<"Status: "<< newStatus << endl;
	cout<<"Info Interest Timed out: "<< infoIntTimedOutCount <<endl;
	//debugging purpose end

	if ( ( oldStatus-newStatus)!= 0 ) // change in Adjacency list
	{
		pnlsr.incrementAdjBuildCount();
		/* Need to schedule event for Adjacency LSA building */
		if ( pnlsr.getIsBuildAdjLsaSheduled() == 0 )
		{
			pnlsr.setIsBuildAdjLsaSheduled(1);
			// event here
			pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(5),
							ndn::bind(&Lsdb::scheduledAdjLsaBuild, pnlsr.getLsdb(), 
																									boost::ref(pnlsr)));
		}
		
	}

	
	
}
