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",
            "AlarmNotificationCond",
            "SMS_Receivers"
        };

        public static string TCC_API_URL = string.Empty;

        public static string TCC_SALTKEY = string.Empty;


        /// <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>
        ///WS Port
        /// </summary>
        private static string AlarmNotificationCond = string.Empty;


        /// <summary>
        ///WSS Port
        /// </summary>
        private static string SMS_Receivers = string.Empty;

        /// <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;
                        case "AlarmNotificationCond":// convert to int type                       
                            {
                                AlarmNotificationCond = ConfigurationManager.AppSettings[key];

                            }
                            break;
                        case "SMS_Receivers":// convert to int type                       
                            {
                                SMS_Receivers = ConfigurationManager.AppSettings[key];

                            }
                            break;
                        default://convert to string type                             
                            break;

                    }
                }
                result = true;

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

            }

            return result;
        }

        public static string GetAlarmNotification_Cond()
        {
            return AlarmNotificationCond;
        }

        public static string GetSMS_Receivers()
        {
            return SMS_Receivers;
        }



        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 };




    }
}
