#include "TwistedPair.h"

namespace cosi {

namespace library {

namespace wiredbas {

std::string TwistedPair::ComponentName = "TwistedPair";
std::string TwistedPair::ComponentType = "Wire";

TwistedPair::TwistedPair(cosi::models::wiredbas::TwistedPairDelay* pDelayModel,
		cosi::models::wiredbas::TwistedPairCost* pCostModel) {
	//Any node
	Name N;
	N.IsBot(false) ;
	N.IsAny(true) ;
	//With EIA-485 interface
	PortInterface P;
	P.SetDirection(PortInterface::INOUT) ;
	P.SetName("EIA-485") ;
	this->SetSource(N) ;
	this->SetSourceInterface(P) ;
	//Define the destination node
	this->SetDestination(N) ;
	this->SetDestinationInterface(P) ;
	this->Directed(false);
	mDelayModel = pDelayModel ;
	mCostModel = pCostModel ;
}

TwistedPair::~TwistedPair() {
}

void TwistedPair::SetDelayModel(cosi::models::wiredbas::TwistedPairDelay* pDelay) {
	mDelayModel = pDelay ;
}

void TwistedPair::SetCostModel(cosi::models::wiredbas::TwistedPairCost* pCost) {
	mCostModel = pCost ;
}

RealDelay TwistedPair::GetDelay(WiringPath pPath) {
	return mDelayModel->Get(pPath);
}

double TwistedPair::GetDelayValue(WiringPath pPath) {
	return mDelayModel->GetValue(pPath);
}

double TwistedPair::GetCost(WiringPath pPath) {
	return mCostModel->GetValue(pPath);
}

cosi::commstruct::wiredbas::PlatformInstance* TwistedPair::GetPlatformInstance(
		int U, std::string pPortU, int V, std::string pPortV) {
	cosi::commstruct::wiredbas::PlatformInstance
			* RetVal = new cosi::commstruct::wiredbas::PlatformInstance("");
	RetVal->AddVertex(U) ;
	(*RetVal)[U].PRJ(Name)IsAny(true);
	(*RetVal)[U].PRJ(Type)IsAny(true);
	(*RetVal)[U].PRJ(Position)IsAny(true);
	Ports PortU;
	PortU.AddPort(pPortU, GetSourceInterface()) ;
	PortU.BoundTo(pPortU, Edge(U, V)) ;
	(*RetVal)[U].PRJ(Ports)Set(PortU);

	RetVal->AddVertex(V) ;
	(*RetVal)[V].PRJ(Name)IsAny(true);
	(*RetVal)[V].PRJ(Type)IsAny(true);
	(*RetVal)[V].PRJ(Position)IsAny(true);
	Ports PortV;
	PortV.AddPort(pPortV, GetDestinationInterface()) ;
	PortU.BoundTo(pPortV, Edge(U, V)) ;
	(*RetVal)[V].PRJ(Ports)Set(PortV);
	RetVal->AddEdge(U, V) ;
	(*RetVal)[Edge(U,V)].PRJ(Name)SetValue(ComponentName);
	(*RetVal)[Edge(U,V)].PRJ(Type)SetValue(ComponentType);
	(*RetVal)[Edge(U,V)].PRJ(WiringPath)IsAny(true);
	return RetVal ;
}

cosi::commstruct::wiredbas::Implementation
			* TwistedPair::GetImplementationInstance(int U, std::string pPortU, int V, std::string pPortV, WiringPath pPath) {
	cosi::commstruct::wiredbas::Implementation
			* RetVal = new cosi::commstruct::wiredbas::Implementation("");
	RetVal->AddVertex(U) ;
	(*RetVal)[U].PRJ(Name)IsAny(true);
	(*RetVal)[U].PRJ(Type)IsAny(true);
	(*RetVal)[U].PRJ(Position)IsAny(true);
	(*RetVal)[U].PRJ(ThreadSet)IsAny(true);
	(*RetVal)[U].PRJ(TransferTable)IsAny(true);
	Ports PortU;
	PortU.AddPort(pPortU, GetSourceInterface()) ;
	PortU.BoundTo(pPortU, Edge(U, V)) ;
	(*RetVal)[U].PRJ(Ports)Set(PortU);

	RetVal->AddVertex(V) ;
	(*RetVal)[V].PRJ(Name)IsAny(true);
	(*RetVal)[V].PRJ(Type)IsAny(true);
	(*RetVal)[V].PRJ(Position)IsAny(true);
	(*RetVal)[U].PRJ(ThreadSet)IsAny(true);
	(*RetVal)[U].PRJ(TransferTable)IsAny(true);
	Ports PortV;
	PortV.AddPort(pPortV, GetDestinationInterface()) ;
	PortV.BoundTo(pPortV, Edge(U, V)) ;
	(*RetVal)[V].PRJ(Ports)Set(PortV);
	RetVal->AddEdge(U, V) ;
	(*RetVal)[Edge(U,V)].PRJ(Name)SetValue(ComponentName);
	(*RetVal)[Edge(U,V)].PRJ(Type)SetValue(ComponentType);
	(*RetVal)[Edge(U,V)].PRJ(WiringPath)Set(pPath);
	return RetVal ;
}

}

}
}
