using System;

namespace Spark3D.Util
{
    /// <summary>
    /// Output text to the console
    /// </summary>
    public class ConsoleOut
    {
        /// <summary>
        /// Output anything when the Debug() function is called
        /// </summary>
        public static bool Debugging = false;
        /// <summary>
        /// Output anything at all
        /// </summary>
        public static bool Slient = false;
        /// <summary>
        /// For application output
        /// </summary>
        /// <param name="s"></param>
        public static void Output(String s, params object[] arg)
        {
            if (!ConsoleOut.Slient)
                Console.WriteLine("[{0}][OUTPUT]  {1}", GetTime(), String.Format(s, arg));
        }
        /// <summary>
        /// For messages, ie ("Started Application").
        /// </summary>
        /// <param name="s"></param>
        public static void Message(String s, params object[] arg)
        {
            if (!ConsoleOut.Slient)
                Console.WriteLine("[{0}][MESSAGE] {1}", GetTime(), String.Format(s, arg));
        }
        /// <summary>
        /// For information, ie ("Welcome to SomeApplication v1.0").
        /// </summary>
        /// <param name="s"></param>
        public static void Info(String s, params object[] arg)
        {
            if (!ConsoleOut.Slient)
                Console.WriteLine("[{0}][INFO]    {1}", GetTime(), String.Format(s, arg));
        }
        /// <summary>
        /// For non critical errors, ie ("Invalid input");
        /// </summary>
        /// <param name="s"></param>
        public static void Error(String s, params object[] arg)
        {
            if (!ConsoleOut.Slient)
                Console.WriteLine("[{0}][ERROR]   {1}", GetTime(), String.Format(s, arg));
        }
        /// <summary>
        /// For critical errors, ie ("Fatal Exception"). Exits application with exit code -1.
        /// </summary>
        /// <param name="s"></param>
        public static void FatalError(String s, params object[] arg)
        {
            if (!ConsoleOut.Slient)
                Console.WriteLine("[{0}][ERROR]   {1}", GetTime(), String.Format(s, arg));
            Environment.Exit(-1);
        }
        /// <summary>
        /// For debugging, ie ("SomeVariable = 5.0").
        /// </summary>
        /// <param name="s"></param>
        public static void Debug(String s, params object[] arg)
        {
            if (ConsoleOut.Debugging && !ConsoleOut.Slient)
                Console.WriteLine("[{0}][DEBUG]   {1}", GetTime(), String.Format(s, arg));
        }
        /// <summary>
        /// Reads input from the console.
        /// </summary>
        /// <param name="s">The input to ask for</param>
        /// <returns>The next line from the console</returns>
        public static String ReadLine(String s, params object[] arg)
        {
            if (!ConsoleOut.Slient)
                Console.Write("[{0}][INPUT]{1}: ", GetTime(), String.Format(s, arg));
            return Console.ReadLine();
        }
        /// <summary>
        /// Retuns the current time in hh:mm:sstt format
        /// </summary>
        /// <returns>The current time</returns>
        public static String GetTime()
        {
            return (DateTime.Now.ToString("hh:mm:sstt"));
        }
    }
}
