using Avalonia;
using System;
using Microsoft.Extensions.Configuration;
using MarketData.Configuration;
using MarketData;
using System.Diagnostics;

namespace PortfolioManager;

sealed 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)
    {
        MDTrace.LogLevel = LogLevel.VERBOSE;
        String strLogFile = "portfolio_manager.log";
        Trace.Listeners.Add(new TextWriterTraceListener(strLogFile));
        MDTrace.WriteLine(LogLevel.DEBUG, "[STARTING]");

        IConfigurationBuilder builder = new ConfigurationBuilder()
        .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
        IConfigurationRoot configurationRoot = builder.Build();
        GlobalConfig.Instance.Configuration = configurationRoot;     // This call sets up configuration stuff so it needs to be first. 
        try { BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); }
        catch (Exception exception) { MDTrace.WriteLine(LogLevel.DEBUG, exception.ToString()); }
    }
    // public static void Main(string[] args) => BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);

    // Avalonia configuration, don't remove; also used by visual designer.
    public static AppBuilder BuildAvaloniaApp()
        => AppBuilder.Configure<App>()
            .UsePlatformDetect()
            .WithInterFont()
            .LogToTrace();
}





