using Avalonia;
using Avalonia.ReactiveUI;
using Serilog;
using System;
using System.Diagnostics;
using VeloeMinecraftLauncher.Utils;

namespace VeloeMinecraftLauncher
{
    internal class Program
    {    
        // Initialization code. Don't use any Avalonia, third-party APIs or any
        // SynchronizationContext-reliant code before AppMain is called: things aren't initialized
        // yet and stuff might break.
        [STAThread]
        public static void Main(string[] args) => BuildAvaloniaApp()
            .StartWithClassicDesktopLifetime(args);

        // Avalonia configuration, don't remove; also used by visual designer.
        public static AppBuilder BuildAvaloniaApp()
        {
            SettingsService.LoadSettings();
            var logger = new LoggerConfiguration()
               .MinimumLevel.Debug()
               .WriteTo.File("avalonia.log", SettingsService.Instance.FileLogEventLevel, fileSizeLimitBytes: SettingsService.Instance.MaxLog * 1024, rollOnFileSizeLimit: true)// restricted... is Optional
               .CreateLogger();
            
            SettingsService.avaloniaLogger = logger;
            TraceListener listener = new SerilogTraceListener.SerilogTraceListener(logger);
            Trace.Listeners.Add(listener);
            
            return AppBuilder.Configure<App>()
                    .UsePlatformDetect()
                    .WithInterFont()
                    .LogToTrace()
                    .UseReactiveUI();
        }
    }
}
