using NEIntelligentControl2.Models.PV;
using NEIntelligentControl2.Service.WebSocket;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NEIntelligentControl2.Models.Messages
{
    /// <summary>
    /// 光伏信息
    /// </summary>
    internal class PVInfoBridge : IMessage
    {
        public List<string> MessageTypes { get; set; } = new List<string>() { "PVInformation".GetConfiguration() };
        public Action<Dictionary<string, PVInfo>> Messaged { get; set; }

        public async Task OnMessage(object message)
        {
            try
            {
                await Task.Run(onmessage);
            }
            catch (Exception e)
            {
                Console.WriteLine($"光伏信息WebSocket数据解析失败：{e.Message}");
            }

            void onmessage()
            {
                var ss = message as Dictionary<string, PVInfo>;
                if (ss == null) return;
                Messaged?.Invoke(ss);
            }
        }
    }
}
