package flow;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;

/**
 * A basic servlet which allows a user to define their code, generate
 * any output, and to select where to transition to next.
 * Last generated by Orchestration Designer at: 2022年2月14日 下午03时02分43秒
 */
public class ser_StrategyNext extends com.avaya.sce.runtime.BasicServlet {

	//{{START:CLASS:FIELDS
	//}}END:CLASS:FIELDS

	/**
	 * Default constructor
	 * Last generated by Orchestration Designer at: 2022年2月14日 下午03时02分43秒
	 */
	public ser_StrategyNext() {
		//{{START:CLASS:CONSTRUCTOR
		super();
		//}}END:CLASS:CONSTRUCTOR
	}

	/**
	 * This method allows for custom integration with other Java components.
	 * You may use Java for sophisticated logic or to integrate with custom
	 * connectors (i.e. JMS, custom web services, sockets, XML, JAXB, etc.)
	 *
	 * Any custom code added here should work as efficiently as possible to prevent delays.
	 * It's important to design your callflow so that the voice browser (Voice Portal/IR)
	 * is not waiting too long for a response as this can lead to a poor caller experience.
	 * Additionally, if the response to the client voice browser exceeds the configured
	 * timeout, the platform may throw an "error.badfetch". 
	 *
	 * Using this method, you have access to all session variables through the 
	 * SCESession object.
	 *
	 * The code generator will *** NOT *** overwrite this method in the future.
	 * Last generated by Orchestration Designer at: 2022年2月14日 下午03时02分43秒
	 */
	public void servletImplementation(com.avaya.sce.runtimecommon.SCESession mySession) {

		// TODO: Add your code here!

	}
	public void updateBranches(Collection branches,
			com.avaya.sce.runtimecommon.SCESession mySession) {
		String NextNodeID = mySession.getVariableField(
				IProjectVariables.NEXT_MENU).getStringValue();
		System.out.println("setnext:NextNodeID:" + NextNodeID);
		String next_node = "end";
		HashMap<String, Object> hMapAll = (HashMap<String, Object>) mySession
				.getVariableField(IProjectVariables.MENU_ALL).getObjectValue();
		HashMap<String, ArrayList<CMenuItemConfig>> hMapChild = (HashMap<String, ArrayList<CMenuItemConfig>>) mySession
				.getVariableField(IProjectVariables.MENU_CHILD)
				.getObjectValue();
		HashMap<String, CMenuConfig> hMapParent = (HashMap<String, CMenuConfig>) mySession
				.getVariableField(IProjectVariables.MENU_PARENT)
				.getObjectValue();
		System.out.println("-"+NextNodeID+"-");
		if (hMapAll.containsKey(NextNodeID)) {
			
			CMenuConfig CMenuConfig = (CMenuConfig) (hMapAll.get(NextNodeID));
			//获取该主目录节点 策略位编码重置
			mySession.getVariableField(IProjectVariables.STRATEGY_ID).setValue(0);
			int MenuType = CMenuConfig.getMenuType();
			String Remark = CMenuConfig.getRemark();
			//节点类型：0开始；1语音播报；2菜单；3servlet，4transfer，5录音;6短信；7收集手机号；8播报结果；9挂机；10 转人工
			switch (MenuType) {
			case 1:// 语音节点
				next_node = "ann";
				break;
			case 2:// 菜单
				//提前给其他手机菜单添加返回的菜单menuID；
				mySession.getVariableField(IProjectVariables.OTHER_PHONE_MENU_ID).setValue(NextNodeID);
				
				next_node = "menu1";
				break;
			case 3:// servlet
				next_node = Remark;
				//设置时间节点目录节点名称
				mySession.getVariableField(IProjectVariables.WORK_TIME_NAME).setValue(NextNodeID);
				mySession.getVariableField(IProjectVariables.NEXT_IDNAME).setValue(NextNodeID);
				break;
			case 6:// 
				next_node ="ser_sendSMS";
				break;
			case 7:// 
				next_node ="annCollectPhone";
				break;
			case 8:// 
				next_node ="annResult";
				break;
			case 9:// 挂机
				next_node = "ser_NodeSQL";
				break;
			case 10:// 转接
				next_node = "ser_transfer";
				break;
			case 11:// 转接
				next_node = "ser_strategy";
				break;
			default:
				break;
			}
			
		} else {

		}
		for (com.avaya.sce.runtime.Goto aGoto : (Collection<com.avaya.sce.runtime.Goto>) branches) {
			aGoto.setNext(next_node);
		}

		System.out.println("--------------------------------------------");
		System.out.println("下一级菜单：" + next_node);

		super.updateBranches(branches, mySession);

	}
	/**
	 * Builds the list of branches that are defined for this servlet object.
	 * This list is built automatically by defining Goto nodes in the call flow editor.
	 * It is the programmer's responsibilty to provide at least one enabled Goto.<BR>
	 *
	 * The user should override updateBranches() to determine which Goto that the
	 * framework will activate.  If there is not at least one enabled Goto item, 
	 * the framework will throw a runtime exception.<BR>
	 *
	 * This method is generated automatically and changes to it may
	 * be overwritten next time code is generated.  To modify the list
	 * of branches for the flow item, override:
	 *     <code>updateBranches(Collection branches, SCESession mySession)</code>
	 *
	 * @return a Collection of <code>com.avaya.sce.runtime.Goto</code>
	 * objects that will be evaluated at runtime.  If there are no gotos
	 * defined in the Servlet node, then this returns null.
	 * Last generated by Orchestration Designer at: 2023年4月14日 下午05时14分30秒
	 */
	public java.util.Collection getBranches(com.avaya.sce.runtimecommon.SCESession mySession) {
		java.util.List list = null;
		com.avaya.sce.runtime.Goto aGoto = null;
		list = new java.util.ArrayList(1);

		aGoto = new com.avaya.sce.runtime.Goto("end", 0, true, "Default");
		list.add(aGoto);

		return list;
	}
}
