//using Anata.Logger;

using AyCode.Core.Enums;
using Microsoft.Extensions.Configuration;

namespace AyCode.Core.Consts
{
    //TODO: Adatbázisból kéne a környezeti beállításokat - J.
    public static class AcEnv
    {
        /// <summary>
        /// Environment.NewLine
        /// </summary>
        // ReSharper disable once InconsistentNaming
        public static string NL => Environment.NewLine;

        //public static AppModeType AppModeServer = AppModeType.Trace;
        ////Elküldeni a kliens-nek, így szerver oldalról tudjuk szabályozni...
        //public static AppModeType AppModeClient = AppModeType.Trace;

        //public static LogLevel LogLevel = LogLevel.Detail;

        public static ulong MaxLogItemsPerSession = 250;

        private static IConfiguration? _appConfiguration = null;
        public static IConfiguration AppConfiguration => _appConfiguration ??= GetAppSettingsConfiguration();

        public static TEnum GetEnum<TEnum>(this IConfiguration configuration, string configPath) where TEnum : struct
            => (TEnum)Enum.Parse(typeof(TEnum), configuration[configPath]);

        public static TEnum GetEnum<TEnum>(this IConfigurationSection section, string configPath) where TEnum : struct
            => (TEnum)Enum.Parse(typeof(TEnum), section[configPath]);

        private static IConfiguration GetAppSettingsConfiguration(string appSettingsFileName = "appsettings.json")
        {
            var config = new ConfigurationBuilder()
                .AddJsonFile(appSettingsFileName)
                .AddEnvironmentVariables() 
                .Build();

            return config;
        }

    }
}