package me.blackphreak;

import me.blackphreak.Debug.Debug;
import me.blackphreak.Debug.DebugLevel;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Lib {
	private static BufferedReader reader = new BufferedReader(
			new InputStreamReader(System.in)
	);
	
	public static String promptQuestion(String question) {
		try {
			System.out.print("\n" + question);
			return reader.readLine();
		} catch (IOException ex) {
			Debug.err("Failed to prompt for question ["+question+"]");
			return "";
		}
	}
	
	public static int tryParseUInt(String inp) {
		return tryParseUInt(inp, "The number you provided is invalid. Please try again.");
	}
	public static int tryParseUInt(String inp, String failMsg) {
		int retn = -1;
		try {
			
			if (!inp.isEmpty() && !inp.isBlank())
			{
				retn = Integer.parseUnsignedInt(inp);
			}
			else
			{
				System.out.println(failMsg);
			}
		} catch (NumberFormatException ex) {
			Debug.log(DebugLevel.ERR.getLevel(), 2, failMsg);
		}
		return retn;
	}
}
