using System;
using System.Text;
using Microsoft.Extensions.Configuration;
using Microsoft.Identity.Client;
using Microsoft.Identity.Client.Extensions.Msal;

namespace Sledgemapper
{
    public static class Program
    {
        private static IConfiguration configuration;
        public static MsalCacheHelper helper;

        [STAThread]
        static void Main()
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath(System.IO.Directory.GetCurrentDirectory())
                .AddJsonFile("appsettings.json");

            configuration = builder.Build();

            // Loading PublicClientApplicationOptions from the values set on appsettings.json



            // Building StorageCreationProperties
            var storageProperties =
                new StorageCreationPropertiesBuilder(CacheSettings.CacheFileName, CacheSettings.CacheDir)
                    .WithLinuxKeyring(
                        CacheSettings.LinuxKeyRingSchema,
                        CacheSettings.LinuxKeyRingCollection,
                        CacheSettings.LinuxKeyRingLabel,
                        CacheSettings.LinuxKeyRingAttr1,
                        CacheSettings.LinuxKeyRingAttr2)
                    .WithMacKeyChain(
                        CacheSettings.KeyChainServiceName,
                        CacheSettings.KeyChainAccountName)
                    .Build();
            // storage = Storage.Create(storageProperties);

            helper = MsalCacheHelper.CreateAsync(storageProperties).Result;

            using (Sentry.SentrySdk.Init("https://973ac1606651454ba7a19f642d0a9bc1@glitchtip.michelescandura.com/1"))
            using (var game = new Sledgemapper())
            {
                Sentry.SentrySdk.CaptureEvent(new Sentry.SentryEvent() { Message = "App starting" });
                game.Run();
            }
        }
    }
}
