import java.util.HashMap;
import java.util.Random;
import java.util.Scanner;

public class VirtualSupportApp {
	private Scanner scanner;
	private Random random;
	private HashMap<String,String> map;
	private String[] randomResponses;
	private String[] technicians = {"Arnold", "Mario", "Elisa", "Mohamad", "Marie"};
	private String technician;

	public static void main(String[] args) {
		VirtualSupportApp app = new VirtualSupportApp();
		boolean processing = true;
		do{
			System.out.print("> ");
			String inquiry = app.read();
			if(inquiry.startsWith("bye") || inquiry.startsWith("Bye")){
				processing = false;
				System.out.println("Goodbye! Have a nice day!");
				System.exit(0);
			}
			app.generateResponse(inquiry);
			
		} while(processing==true);
	}

	public VirtualSupportApp(){
		init();
	}
	
	private void init(){
		scanner = new Scanner(System.in);
		random = new Random();
		map = new HashMap<>();
		technician = technicians[random.nextInt(technicians.length)];
		randomResponsesDatabase();
		responseDatabase();
		welcome();
	}
	
	private void welcome(){
		System.out.println("****************************************************");
		System.out.println("****************************************************");
		System.out.println("***                     ~~~                      ***");
		System.out.println("*** WELCOME TO THE COMPUTER TECH SUPPORT SYSTEM! ***");
		System.out.println("***                     ~~~                      ***");
		System.out.println("***                  Ver. 1.0                    ***");
		System.out.println("****************************************************");
		System.out.println("****************************************************");
		System.out.println("*  May problema ang computer mo? Itanong mo lang.  *");
		System.out.println("*   Tutulungan kitang i-solve ang problema.        *");
		System.out.println("*                                                  *");
		System.out.println("*        I-TIPA SA ENGLISH ANG PROBLEMA.           *");
		System.out.println("*          or I-TIPA ang BYE to exit.              *");
		System.out.println("****************************************************\n");
		System.out.println("Hi, my name is " + technician + ". I am your computer technician today.");
		System.out.println("What can I do for you?\n");
	}
	
	private String read(){
		return scanner.nextLine();
	}

	private void generateResponse(String inquiry){
		String[] inquiryArray = inquiry.trim().toLowerCase().split(" ");
		String randomText = inquiryArray[random.nextInt(inquiryArray.length)];
		response(randomText);
	}
	
	private void response(String randomText){
		String answer = map.get(randomText);
		if(answer != null){
			System.out.println(technician + ": " + answer);
		} else {
			int index = random.nextInt(randomResponses.length);
			String randResponse = getRandomResponse(index);
			System.out.println(technician + ": " + randResponse);
		}
	}
	
	private void responseDatabase(){
		map.put("windows", "Your operating system has know issues at the moment. You need to get the latest update.");
		map.put("slow", "It could be because you have process running all at the same time. Limit running applications.");
		map.put("virus", "If you have an antivirus installed, that could help prevent attack that is slowing down your system.");
		map.put("login", "It could be a problem of the OS access control. You need to refer to your OS manual.");
		map.put("hard", "That is interesting. Tell me more.");
		map.put("wifi", "Make sure you have internet available and your router is working.");
		map.put("internet", "I need more more information. Explain more.");
		map.put("system", "Maybe your operating system is old. Upgrade to windows 10.");
		map.put("harddrive", "Make sure you have enough space left. Delete some files.");
		map.put("monitor", "Make sure to turn on the power and check cable. Getting the latest driver helps.");
	}

	private void randomResponsesDatabase(){
		randomResponses = new String[10];
		randomResponses[0] = "Can you elaborate more?";
		randomResponses[1] = "Sorry, can you explain it little further?";
		randomResponses[2] = "Your question is not clear yet. Can you tell me more details about it?";
		randomResponses[3] = "I did not get that. What is the problem again?";
		randomResponses[4] = "Tell me more about the symptoms.";
		randomResponses[5] = "The last part that you said. Can you explain that?";
		randomResponses[6] = "Oic. What else had happened after that?";
		randomResponses[7] = "What did you do before that happened?";
		randomResponses[8] = "Can you do any work on it? Is it functional still?";
		randomResponses[9] = "What else can you tell me about it?";
	}
	
	private String getRandomResponse(int i){
		return randomResponses[i];
	}
	
}

