using System;
using System.ServiceProcess;
using System.Collections.Generic;
using System.Collections.Concurrent;

using FilterAPI;
using FilterAPI.Networking;

using FilterLogin.LocalHandlers;
using FilterLogin.LocalNetworking;

using FilterLogin.LoginHandlers;
using FilterLogin.LoginNetworking;
using System.Threading;

namespace FilterLogin
{
    internal class Program
    {
        public static String ServiceName = "Login";

        public static Authentication Auth;
        public static Database SQL;

        public static LocalClient LocalClient;
        public static LocalHandlerLoader LocalHandlers;

        public static LoginHandlerLoader LoginHandlers;

        public static ConcurrentDictionary<Guid, LoginClient> LoginClients = new ConcurrentDictionary<Guid, LoginClient>();



        private static void Main()
        {
			if (Environment.UserInteractive)
			{
				Service s = new Service();
				s.Init(); // Init() is pretty much any code you would have in OnStart().
				while (true) { Thread.Sleep(1); }
			}
			else
			{
				ServiceBase[] ServicesToRun = new ServiceBase[] { new Service() };
				ServiceBase.Run(ServicesToRun);
			}
		}

        public static void SendConsoleText(ConsoleColor WriteColor, String Text, params Object[] Args)
        {
            String FormattedText = String.Format(Text, Args);

            using (var ClientPacket = new Packet(2, 3))
            {
                ClientPacket.PacketWriter.Write(ConsoleColorConverter.ConsoleColorToID(WriteColor));
                ClientPacket.PacketWriter.Write(ServiceName);
                ClientPacket.PacketWriter.Write(FormattedText);

                if (LocalClient != null) { LocalClient.SendPacket(ClientPacket); }
            }
        }
    }
}
