using System.Net.WebSockets;
using System.Text;
using System.Text.Json;
using BLWData.Entity;
using CommonEntity;
using CommonTools;
using MessagePack;
using Newtonsoft.Json;

namespace ConsoleApp2
{
    internal class Program
    {
        static void tsa(string body)
        {


            try
            {
                NengHao? poo = System.Text.Json.JsonSerializer.Deserialize<NengHao>(body);

                if (string.IsNullOrEmpty(poo.HostNumber))
                {
                    return;
                }
                if (poo.NengHaoList == null || poo.NengHaoList.Count == 0)
                {
                    return;
                }


                #region 宝镜系统使用的能耗数据结构
                List<DeviceData> la = new List<DeviceData>();
                foreach (var item in poo.AllDeviceData)
                {
                    DeviceData dd = new DeviceData();
                    dd.HostID = item.HostID;
                    dd.DeviceType = item.DeviceType;
                    dd.Address = item.Address;
                    dd.Brightness = item.Brightness;
                    dd.Status = item.Status;
                    dd.CurrentTemp = item.CurrentTemp;
                    dd.SettingTemp = item.SettingTemp;
                    dd.Mode = item.Mode;
                    dd.FanSpeed = item.FanSpeed;
                    dd.Valve = item.Valve;
                    la.Add(dd);
                }


                List<SinglePowerChannelData> nenghaolist = new List<SinglePowerChannelData>();
                if (poo.NengHaoList != null && poo.NengHaoList.Count > 0)
                {
                    foreach (var item in poo.NengHaoList)
                    {
                        SinglePowerChannelData gs1 = new SinglePowerChannelData();
                        gs1.Address = item.address;
                        gs1.Dianliu = item.dianliu;
                        gs1.Dianya = item.dianya;
                        gs1.Gonglv = item.gonglv;
                        gs1.Nenghao = item.nenghao;
                        gs1.Zongnenghao = item.zongnenghao;
                        nenghaolist.Add(gs1);
                    }

                }
                //宝镜系统使用
                //EnergyConsumption ese = new EnergyConsumption();
                //ese.HotelCode = poo.HotelCode;
                //ese.HostNumber = poo.HostNumber;
                //ese.Mac = poo.Mac;
                //ese.EndPoint = poo.EndPoint;
                //ese.PowerChannelList.AddRange(nenghaolist);
                ////ese.V = poo.V;
                ////ese.A = poo.A;
                ////ese.P = poo.P;
                ////ese.EnergyConsumption_ = poo.Energy_Consumption;
                ////ese.SumEnergyConsumption = poo.Sum_Energy_Consumption;
                //ese.CreateTime = poo.CreateTime;
                //ese.RoomNumber = poo.RoomNumber ?? "";
                //ese.IsTakeCard = poo.IsTakeCard;
                //ese.IsInsertCard = poo.IsInsertCard;
                //ese.CarbonVIP = poo.CarbonVIP;
                //ese.DeviceStatusList.AddRange(la);
                //ese.IdentityInfo = poo.IdentityInfo;
                //ese.CardEvent = poo.CardEvent;
                //ese.PMSStatus = poo.PMS_Status;
                //ese.BrightG = poo.Bright_G;

                //byte[] data = ese.ToByteArray();
                //string TopicKey1 = KafkaKey.BLWLog4BaoJing_RCU_Topic;
                //string DetailKey1 = KafkaKey.UDPPackagePowerMonitor;



                if (poo.HotelCode == 2302)
                {
                }

                #endregion
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
        }
        static void Main(string[] args)
        {

            string YYY111111 = File.ReadAllText("2.txt");

            tsa(YYY111111);
            Console.WriteLine("Hello, World!");

            NengHao? csdn = System.Text.Json.JsonSerializer.Deserialize<NengHao>(YYY111111);

            var o = JsonConvert.DeserializeObject<CommonEntity.OnOffLineData>(YYY111111);
            string afds = "hello";
            string dda = afds;
            dda = "world";
            Console.WriteLine(afds);

            string YYY = File.ReadAllText("3.txt");
            NengHao? poo = System.Text.Json.JsonSerializer.Deserialize<NengHao>(YYY);
            byte[] qf = MyMessagePacker.FastSerialize(poo);


            ////宝镜系统使用
            //EnergyConsumption ese = new EnergyConsumption();
            //ese.HotelCode = poo.HotelCode;
            //ese.HostNumber = poo.HostNumber;
            //ese.Mac = poo.Mac;
            //ese.EndPoint = poo.EndPoint;
            //ese.V = poo.V;
            //ese.A = poo.A;
            //ese.P = poo.P;
            //ese.KWH = poo.KW_H;
            //ese.SumKWH = poo.Sum_KW_H;
            //ese.CreateTime = poo.CreateTime;
            //ese.IsTakeCard = poo.IsTakeCard;
            //ese.RoomNumber = poo.RoomNumber;
            //ese.CarbonVIP = poo.CarbonVIP;

            //byte[] data = ese.ToByteArray();
            //string TopicKey1 = KafkaKey.BLWLog4BaoJing_RCU_Topic;
            //string DetailKey1 = KafkaKey.UDPPackageWholeDataMonitor;
            string[] NNN = "34-D0-B8-11-80-80".Split('-');
            string n1 = NNN[4];
            string n2 = NNN[5];
            byte bbn1 = Convert.ToByte(n1, 16);
            byte bbn2 = Convert.ToByte(n2, 16);
            short MAC1 = Convert.ToInt16(bbn1);
            short MAC2 = Convert.ToInt16(bbn2);
            string HOSTNUMBER = "099008" + MAC1 + MAC2;

            string nnn = File.ReadAllText("1.txt");
            UDPPackage? usa = System.Text.Json.JsonSerializer.Deserialize<UDPPackage>(nnn);
            AAA a = new AAA();
            MyClass mm = new MyClass();
            mm.Age = 30;
            mm.FirstName = "Test";
            mm.LastName = "我是一从此非常大霏霏 的数据";
            a.MyClass = new List<MyClass> { mm };
            var asd = System.Text.Json.JsonSerializer.Serialize(a);

            var qqfa = Encoding.UTF8.GetBytes(asd.ToString());

            //byte[] qf = MyMessagePacker.FastSerialize(mm);
            string uuu = MyMessagePacker.FastDeserialize<string>(qf);
            AAA uuu111 = MyMessagePacker.FastDeserialize<AAA>(qf);
            //Console.WriteLine(uuu.MyClass.FirstOrDefault().FirstName);

            Console.WriteLine("Hello, World!");
        }
        public static void google_parse()
        {
            EnergyConsumption e = new EnergyConsumption();

            byte[] bbb = new byte[] { };
            e = EnergyConsumption.Parser.ParseFrom(bbb);

        }
    }

    [MessagePackObject]
    public class ItsClass
    {
        [Key(0)]
        public string Data { get; set; }
    }
    [MessagePackObject]
    public class MyClass
    {
        // Key attributes take a serialization index (or string name)
        // The values must be unique and versioning has to be considered as well.
        // Keys are described in later sections in more detail.
        [Key(0)]
        public int Age { get; set; }

        [Key(1)]
        public string FirstName { get; set; }

        [Key(2)]
        public string LastName { get; set; }

        // All fields or properties that should not be serialized must be annotated with [IgnoreMember].
        [IgnoreMember]
        public string FullName { get { return FirstName + LastName; } }
    }
    [MessagePackObject()]
    public class AAA
    {
        [Key(0)]
        public List<MyClass> MyClass { get; set; }

    }
}
