using Microsoft.Practices.Unity;
using Neudesic.Tools.CodeDebt.IoC;
using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace Neudesic.Tools.CodeDebt
{
	internal class Program
	{
		private static void Main(string[] args)
		{
			if (args.Length < 2)
			{
				Console.WriteLine("Usage:");
				Console.WriteLine("\tCodeDebtTool <codeBase> <projectPath1> <projectPath2> <projectPath3>...\r\n\r\n");
				Console.WriteLine("\tWhere <codeBase> is a repository and <projectPath> is local project path.");
			}
			else
			{
				List<string> projectPaths = new List<string>();
				projectPaths.AddRange(args);	//Adds all incoming arguments to collection
				projectPaths.RemoveAt(0);		//Removes the codebase argument
				CollectCodeDebt(args, projectPaths);
			}
#if DEBUG
			WaitForKeyPress();
#endif
		}

		private static void CollectCodeDebt(string[] args, List<string> projectPaths)
		{
			DependencyManager.Bootstrap(
				(container) =>
				{
					container.RegisterType(typeof(CodeDebtReporter), new ContainerControlledLifetimeManager());
					container.RegisterType(typeof(CodeDebtCollector), new ContainerControlledLifetimeManager());
				});
			CodeDebtReporter debtReporter = DependencyManager.Instance.Resolve<CodeDebtReporter>();
			debtReporter.ReportCodeDebt(args[0], projectPaths);
		}

#if DEBUG

		private static void WaitForKeyPress()
		{
			if (Debugger.IsAttached)
			{
				Console.WriteLine("Press any key to continue...");
				Console.ReadLine();
			}
		}

#endif
	}
}