using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Configuration;

namespace EVCB_OCPP.WSServer
{
    public static class GlobalConfig
    {
        public static List<string> ConfigKeys = new List<string>()
        {
            "WSPort",
            "WSSPort",
            ""
        };


        /// <summary>
        /// 預設心跳間隔時間 單位:秒
        /// </summary>
        private static int DEFAULT_HEARTBEAT_INTERVAL = 60;



        /// <summary>
        ///WS Port
        /// </summary>
        private static int WS_Port = 2012;


        /// <summary>
        ///WSS Port
        /// </summary>
        private static int WSS_Port = 2013;

        /// <summary>
        /// Load setting from app.config 
        /// </summary>
        public static bool LoadAPPConfig()
        {
            bool result = false;
            string key = string.Empty;
            try
            {

                for (int i = 0; i < ConfigKeys.Count; i++)
                {
                    key = ConfigKeys[i];
                    switch (key)
                    {
                        case "WSPort":// convert to int type                       
                            {
                                var value = ConfigurationManager.AppSettings[key];

                                WS_Port = Convert.ToInt32(value);
                            }
                            break;
                        case "WSSPort":
                            {
                                var value = ConfigurationManager.AppSettings[key];

                                WSS_Port = Convert.ToInt32(value);
                            }
                            break;
                        default://convert to string type                             
                            break;

                    }
                }
                result = true;

            }
            catch (Exception ex)
            {
                Console.WriteLine(key + " Load from APPConfig " + ex.ToString());

            }

            return result;
        }



        public static int GetWS_Port()
        {
            return WS_Port;
        }


        public static int GetWSS_Port()
        {
            return WSS_Port;
        }

        public static int GetHEARTBEAT_INTERVAL()
        {
            return DEFAULT_HEARTBEAT_INTERVAL;
        }

        public static readonly int DB_DefaultConnectionTimeout = 60;
        public static readonly string UTC_DATETIMEFORMAT = "yyyy/MM/dd'T'HH':'mm':'ss'Z'";
        /// <summary>
        /// 預設 Null的 DateTime 
        /// </summary>
        public static DateTime DefaultNullTime = new DateTime(1991, 1, 1);

        public static JsonSerializerSettings JSONSERIALIZER_FORMAT = new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None };




    }
}