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

namespace NEIntelligentControl2.Service.Alarm
{
    /// <summary>
    /// 报警管理
    /// </summary>
    public class AlarmManager
    {
        public Action<List<FaultInfoModel>> OnFaultCount { get; set; }
        public Action<List<AlarmInfo>> OnAlarmCount { get; set; }


        private MessageBridge _MessageBridge;
        private FaultCountBridge _FaultCountBridge;
        private AlarmCountBridge _AlarmCountBridge;
        public AlarmManager(MessageBridge mb)
        {
            _MessageBridge = mb;
            _FaultCountBridge = new FaultCountBridge() { Messaged = OnFaultCountMessaged };
            _AlarmCountBridge = new AlarmCountBridge() { Messaged = OnAlarmCountMessaged };
            _MessageBridge.Register(_FaultCountBridge);
            _MessageBridge.Register(_AlarmCountBridge);
        }

        private void OnAlarmCountMessaged(List<AlarmInfo> obj)
        {
            try
            {
                OnAlarmCount?.Invoke(obj);
            }
            catch { }
        }

        private void OnFaultCountMessaged(List<FaultInfoModel> fims)
        {
            try
            {
                OnFaultCount?.Invoke(fims);
            }
            catch { }
        }
    }
}
