package com.example.bot.spring.textsender;

import com.example.bot.spring.database.*;

public class SQTextSender implements TextSender {
	private SQDBEngine sqdbengine; 

	public SQTextSender() {
		// TODO Auto-generated constructor stub
		this.sqdbengine = new SQDBEngine();
	}
	
	@Override
	public String process(String userId, String msg) throws Exception{
		if(msg == null) {
			throw new Exception("unvalid input for SQTextSender.");
		}
		// TODO Auto-generated method stub
		/* Label: greeting/ thanks/ goodbye */
		String label = null; 
		
		try {
		// if msg contains certain keywords, label it
			
			label = sqdbengine.search(msg);
			label = label.replaceAll("\\s+$", "");	// trunc the whitespace at the end 
			
			//int length = label.length();
			//System.out.print(length);
			
			/*
			if (msg == "Hi") {
				label = "greeting";
			}
			*/
		}catch (Exception e){
			System.out.println("---------- inside SQTextSender ---------- ");
			System.err.println(e.getMessage());
			e.printStackTrace();
		}
		
		switch (label) {
			case "greeting":{
				System.out.print("should be here");
				return "Hi! How can I help you?";
			}
			case "thanks":{
				return "You are welcome =)";
			}
			case "goodbye":{
				return "have a nice day!";
			}
			default:{
				throw new Exception("Not a simple question");
			}
		}			
	}
}

@@ -542,19 +542,8 @@
 l; %0A
-%09%09%0A%09%09try %7B%0A
 %09%09//
@@ -586,16 +586,16 @@
 abel it%0A
+
 %09%09%09%0A%09%09%09l
@@ -843,168 +843,9 @@
 %09*/%0A
-%09%09%7Dcatch (Exception e)%7B%0A%09%09%09System.out.println(%22---------- inside SQTextSender ---------- %22);%0A%09%09%09System.err.println(e.getMessage());%0A%09%09%09e.printStackTrace();%0A%09%09%7D
 %0A
+
 %09%09%0A%09
@@ -1151,14 +1151,11 @@
 %09%09%7D%0A
+
 %09%09%7D
-%09%09%09
 %0A%09%7D%0A

fix small bug #2