using System;
using System.ServiceProcess;

using FilterAPI;
using FilterAPI.Networking;

using FilterRest.LocalHandlers;
using FilterRest.LocalNetworking;

namespace FilterRest
{
    internal class Program
    {
        public static String ServiceName = "Rest";

        public static Authentication Auth;
        public static Database SQL;

        public static LocalClient LocalClient;
        public static LocalHandlerLoader LocalHandlers;

        private static void Main()
        {
            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); }
            }
        }
    }
}
