<%@page language="java" contentType="application/json;charset=UTF-8"
	pageEncoding="UTF-8"%>
<%!// Implement this method to execute some server-side logic.
	public JSONObject performLogic(JSONObject state, Map<String, String> additionalParams) throws Exception {
		Logger logger = LogManager.getLogger("Backend");
		// The state variable contains all variables from the application.
		// If the application is a callflow, this consists of the variables in the Entry block 
		// of the callflow.  If the application is a workflow, the project variables will 
		// be passed.
		// For callflows, it's possible for the state variable to be null, if the 
		// passState option of the Backend block is false.

		// Example of how to access data from the state object.
		// Note that "Input1" is the name of the Input block and 
		// "Var1" is the name of the user-defined variable.

		// String userInput = state.getString("Input1");
		// String userVariable = state.getString("Var1");

		// The additionalParams map contains any additional input parameters passed
		// in the backend logic block.

		// Example:
		// Note that "Param1" is the parameter name of the input parameter.
		// String param = additionalParams.get("Param1");
		String sessionID = state.getString("GVPSessionID");
		int index = sessionID.indexOf(";");
		//remove the non-session info from sessionID
		if (index > 0) {
			sessionID = sessionID.substring(0, index);
		}
		String logKey = "SessionID=" + sessionID + " ANI=" + state.getString("ANI") + " ";
		if (state != null) {
			//String input = state.getString("root.vistaString");
		}

		JSONObject backendOutput = new JSONObject();

		// Finally, this method must return a result object.  Any values stored in 
		// this result object will be reassigned to output parameters defined in the voice application.
		// For example, if the voice application declares an output parameter called "OutParam",
		// the output parameter will get the value "Value".

		// result.put("OutParam", "Value");
		if (additionalParams != null) {
			//logger.debug(logKey + "Additional Params vistaString=" + additionalParams.get("vistaString"));
			try {
				JSONObject backendInputObj = new JSONObject(additionalParams.get("backendInput"));
				if (backendInputObj != null) {
					//add sessionID, ANI and start time for logging
					backendInputObj.put("sessionID", sessionID);
					backendInputObj.put("ANI", state.getString("ANI"));
					//logger.debug(logKey + "Additional Params backendInput object=" + backendInputObj);
					long beginTime = System.currentTimeMillis();
					backendOutput = new BackendManager().callProxy(backendInputObj);
					long endTime = System.currentTimeMillis();
					long respTime = endTime - beginTime;
					logger.info(logKey + " Got WS response in [" + respTime + " ms] for service ["
							+ backendInputObj.getString("svcName") + "]");

				}
			} catch (Exception e) {
				logger.error(logKey + "Got exception - " + e.toString() + " with message " + e.getMessage());
				e.printStackTrace();
			}
		}
		//logger.debug(logKey + "Backend Returning JSON - " + backendOutput.toString());
		//logger.debug(new Date() + "Backend Returning AcctList  - " + backendOutput.get("acctList").getClass());
		//additionalParams.put("backendOutput", backendOutput.toString());
		return backendOutput;

	};%>
<%-- GENERATED: DO NOT REMOVE --%>
<%@page import="org.json.JSONObject"%>
<%@page import="org.json.JSONException"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.Date"%>
<%@page import="com.truist.backend.BackendManager"%>
<%@page import="org.apache.logging.log4j.Logger"%>
<%@page import="org.apache.logging.log4j.LogManager"%>
<%@include file="../include/backend.jspf"%>