using System;
using System.Reflection;
using System.Text;
using SlatedGameToolkit.Tools.Commands;
using SlatedGameToolkit.Tools.CommandSystem;
using SlatedGameToolkit.Tools.CommandSystem.Interaction;

namespace SlatedGameToolkit.Tools
{
    class Program
    {
        static private bool live;
        static void Main(string[] args)
        {
            CommandMap commands = new CommandMap();
            commands.Add(new StopCommand());
            commands.Add(new HelpCommand(commands));
            commands.Add(new ListEmbeddedResourcesCommand());
            commands.Add(new GraphicalPlaygroundCommand());
            CommandProcessor processor = new CommandProcessor(commands);
            AssemblyName name = Assembly.GetExecutingAssembly().GetName();
            IInteractable interactable = (args.Length > 0 ? (IInteractable) new SingleConsoleInteraction(string.Join(' ', args)) : (IInteractable) new ConsoleInteraction("Tools"));
            interactable.Tell(String.Format("{0} Version: {1}", name.Name, name.Version));
            if (args.Length > 0) {
                interactable.Tell("Running in one time use mode.");
                processor.Process(interactable);
            } else {
                interactable.Tell("Welcome to SlatedGameToolkit.Tools! These tools are meant for the developers using the SlatedGameToolkit. Type \"help\" for a list of things this tool can currently do.");
                live = true;
                while (live) {
                    processor.Process(interactable);
                }
            }
            interactable.Tell("Exiting tool.");
            commands.Dispose();
        }

        public static void Stop() {
            live = false;
        }
    }
}
