using Log;
using System.Threading.Channels;
using Universal;

namespace OnlineLogViewer;

internal class Program
{
    static void Main(string[] args)
    {
        while (true)
        {
            Console.WriteLine("IP:");
            string? IP = Console.ReadLine();
            Console.WriteLine("Port:");
            string? _port = Console.ReadLine();
            Console.WriteLine("LogLevel: ");
            Console.WriteLine("Info = 1");
            Console.WriteLine("Warning = 2");
            Console.WriteLine("Error = 3");
            Console.WriteLine("Fatal = 4");
            Console.WriteLine("Debug = 5");
            string? _level = Console.ReadLine();
            if (string.IsNullOrEmpty(IP) || string.IsNullOrEmpty(_port))
            {
                Console.WriteLine("Error");
                continue;
            }

            if (!int.TryParse(_level, out int level) || !level.In(0, 1, 2, 3, 4, 5))
            {
                Console.WriteLine("Error");
                continue;
            }
            if (!int.TryParse(_port, out int port))
            {
                Console.WriteLine("Error");
                continue;
            }
            LogHub logHub = new();
            if (!logHub.Initialize(IP, port, "LogHub", (LogLevel)level))
            {
                Console.WriteLine("Connect failed");
                continue;
            }
            break;
        }

        Thread.Sleep(-1);
    }
}
