package com.mycompany.server;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.google.gwt.user.client.rpc.IsSerializable;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.mycompany.client.ServiceNodeRecord;
import com.mycompany.client.ServiceNodesService;

/**
 * The server side implementation of the RPC service.
 */
@SuppressWarnings("serial")
public class ServiceNodesServiceImpl 
		extends RemoteServiceServlet 
		implements ServiceNodesService, Serializable, IsSerializable {

/*	
	public List<ServiceNodeRecord> xfetch() {
		
		// mule initialisation
		BccMule mule = BccMule.getBccMule();
		
		String embassyCode = "foo";		// using test values - this will not have any effect. TODO verify with Jam
		
		// create a request
		ServiceNodesRequest request = makeRequest(embassyCode);		
			
		// submit it through mule
		ServiceNodesResponse response = mule.send(request, 10000);
		
		List<ServiceNodeRecord> list = new ArrayList<ServiceNodeRecord>();
		
		ServiceNodeRecord record = null;
	    ServiceNodes nodes = response.getServiceNodes();
		int id = 1;
		for (ServiceNode node: nodes.getServiceNode()) {
			record = new ServiceNodeRecord();
			record.setId(id++);
			record.setNodeId(node.getNodeId());
			record.setInstitutionCode(response.getInstitutionCode());
			record.setServiceName(node.getName());
			record.setShortAddress(node.getShortAddress());
			record.setNodeType(node.getNodeType() + "");	// Note: long types are coerced to string
			record.setServiceInfo(node.getInfo());
			record.setAddress(node.getAddress());
			record.setPort(node.getPort() + "");
			record.setStatus(node.getStatus());
			record.setColor(node.getColor());
			record.setStatus(node.getStatus());
			record.setCreated(node.getCreated());
			record.setSetInactive(node.getSetInactive());
			record.setXpos(node.getXpos());
			record.setXlen(node.getXlen());
			record.setYpos(node.getYpos());
			record.setYlen(node.getYlen());
			list.add(record);				
		}
		
		return list;		
	}
*/
	
	public ServiceNodeRecord add(ServiceNodeRecord record) {
		// TODO Auto-generated method stub
		return null;
	}

	public void remove(ServiceNodeRecord record) {
		// TODO Auto-generated method stub
		
	}

	public ServiceNodeRecord update(ServiceNodeRecord record) {
		// TODO Auto-generated method stub
		return null;
	}
	

//	List<ServiceNodeRecord> list = new ArrayList<ServiceNodeRecord>();	
	
	static List<ServiceNodeRecord> list;
	static int id;	
	// load static data for testing
	static {
		id = 1;
		list = new ArrayList<ServiceNodeRecord>();
		ServiceNodeRecord record;		
		record = new ServiceNodeRecord();		
		record.setId(id++);
		record.setServiceName("First");
		record.setInstitutionCode("C2");
		record.setServiceInfo("info1");
		record.setShortAddress("shortAddress1");
		record.setNodeType("HUB1");
		list.add(record);

		record = new ServiceNodeRecord();				
		record.setId(id++);
		record.setServiceName("Second");
		record.setInstitutionCode("C2");
		record.setServiceInfo("info2");
		record.setShortAddress("shortAddress2");
		record.setNodeType("HUB2");
		list.add(record);
		
		record = new ServiceNodeRecord();				
		record.setId(id++);
		record.setServiceName("Third");
		record.setInstitutionCode("C2");
		record.setServiceInfo("info3");
		record.setShortAddress("shortAddress3");
		record.setNodeType("HUB3");
		list.add(record);
		
		record = new ServiceNodeRecord();				
		record.setId(id++);
		record.setServiceName("Fourth");
		record.setInstitutionCode("C2");
		record.setServiceInfo("info4");
		record.setShortAddress("shortAddress4");
		record.setNodeType("HUB4");
		list.add(record);
	}
	
	public List<ServiceNodeRecord> fetch() {
		return list;		
	}
	
}
