package com.armundia.app.test;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;

import javax.enterprise.context.Dependent;
import javax.inject.Inject;

import com.armundia.app.test.pojo.TestPojo;
import com.armundia.core.websocket.WebSocket;
import com.armundia.core.websocket.pojo.SessionContainer;

@Dependent
public class TestManager implements Serializable {
	private static final long serialVersionUID = -2171861953576091979L;

	private final Logger logger = Logger.getLogger(this.getClass().getName());
	
	@Inject
	private WebSocket webSocket;
	
	private String test = "";
	
	
	public void test(TestPojo testPojo, SessionContainer sessionContainer) {
		logger.info("Testing Stateful bean");
		test = testPojo.test + ' ' + test;
		logger.info(test);
		
		this.testSocketToAll();
		this.testSocketToSession(sessionContainer);
	}
	
	public void testSocketToAll() {
		Map<String, Object> params = new HashMap<>();
		params.put("toALL", true);
		params.put("message", "This is a global message");
		
		webSocket.emit("test-response", params);
	}
	
	public void testSocketToSession(SessionContainer sessionContainer) {
		Map<String, Object> params = new HashMap<>();
		params.put("toSingleSession", true);
		params.put("message", "This is a message for a single session");
		
		webSocket.emit("test-response", params, sessionContainer);
	}
}
