using Nest;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XYY.Common.Standard
{
    public class EsClientManager
    {
        public class ChargesLog
        {
            public string Number
            {
                get; set;
            }

            public long Millise
            {
                get; set;
            }

            public string Time
            {
                get; set;
            }

            public Dictionary<string, long> TimeList
            {
                get; set;
            }

            public long TimeLong
            {
                get; set;
            }
        }

        private readonly static object lockObj = null;
        static EsClientManager()
        {
            lockObj = new object();
        }

        private static ElasticClient _weightLogClient;
        public static ElasticClient WeightLogClient
        {
            get
            {
                if (_weightLogClient == null)
                {
                    lock (lockObj)
                    {
                        if (_weightLogClient == null)
                        {
                            string addr = "http://120.24.149.148:9526";
                            Uri node = new Uri(addr);
                            var settings = new ConnectionSettings(node).DefaultMappingFor<ChargesLog>(x =>
                            x.IndexName("chargeslog")
                            .TypeName("log")
                            .IdProperty(y => y.Number));
                            _weightLogClient = new ElasticClient(settings);
                        }
                    }
                }
                return _weightLogClient;
            }
        }

    }
}
