package org.gateway.home.tmaestroTeacherService.iface;

import java.util.Hashtable;
import java.util.Set;
import java.util.Vector;

import org.osgi.framework.BundleContext;

public class TMaestroTeacherServiceHandle {
	
	private TMaestroTeacherServiceImpl tmaestroTeacherService = null;
	
	private BundleContext context;
	
	private Hashtable<String, TeacherToolsGroup> teacherToolsGroups = new Hashtable<String, TeacherToolsGroup>();

	public TMaestroTeacherServiceHandle(TMaestroTeacherServiceImpl tmaestroTeacherService, BundleContext ctx) {
		// TODO Auto-generated constructor stub
		teacherToolsGroups = new Hashtable<String, TeacherToolsGroup>();
		this.tmaestroTeacherService = tmaestroTeacherService;
		this.context = ctx;
	}
	
	public Hashtable<String, TeacherToolsGroup> getTeacherToolsGroups() {
		return this.teacherToolsGroups;
	}
	
	public void addTeacherToolsGroup(TeacherToolsGroup toolsGroup) {
		teacherToolsGroups.put(toolsGroup.getId(), toolsGroup);
	}
	
	public void removeTeacherToolsGroup(String toolsGroupId) {
		teacherToolsGroups.remove(toolsGroupId);
	}
	
	public String getListTeacherToolsGroup() {
		String currentChildList = "";
		TeacherToolsGroup toolsGroup = null;
		
		Set<String> keys = teacherToolsGroups.keySet();
		
		for (String key : keys) {
			toolsGroup = teacherToolsGroups.get(key);
			
			if (currentChildList.equals("")) {
				currentChildList = "teacherToolsGroup" + "." + toolsGroup.getId();
			}
			else {
				currentChildList = currentChildList + "," + "teacherToolsGroup" + "." + toolsGroup.getId();
			}
		}
		
		
		return currentChildList;
	}
	
	public Hashtable<String, TeacherToolsGroup> loadTeacherTools() {
		this.teacherToolsGroups = new Hashtable<String, TeacherToolsGroup>();
		
		TeacherTool tool = new TeacherTool();
		tool.setId("Authoring"+"_"+"Reload");
		tool.setItemName("Reload");
		tool.setTitle("Adaptative course authoring tool");
		tool.setToolsGroup("Authoring");
		tool.setState("OFF");
		//tool.setIcon("http://localhost:8080/reload/icon.jpg");
		tool.setIcon(TMaestroTeacherServiceImpl.icon);
		tool.setLitteIcon("photo");
		//tool.setTargetUrl("http://localhost:8080/reload/reload.jnlp");
		tool.setTargetUrl(TMaestroTeacherServiceImpl.reloadURL);
		tool.setDescription("Course authoring tool");
		
		TeacherToolsGroup toolsGroup = new TeacherToolsGroup();
		toolsGroup.setId(tool.getToolsGroup());
		toolsGroup.setItemName(tool.getToolsGroup());
		toolsGroup.setTitle(tool.getToolsGroup());
		toolsGroup.setState("OFF");
		
		toolsGroup.addTeacherTool(tool);
		
		addTeacherToolsGroup(toolsGroup);
		
		return this.teacherToolsGroups;
	}

}
