using System.Collections.Generic;
using System.Windows.Media;
using Aitex.Core.RT.Event;
using Aitex.Core.UI.MVVM;

namespace Aitex.Core.UI.View.Common
{
    public class MonitorViewModel : ViewModelBase
    {
        public List<AlarmItem> AlarmEvents { get; set; }

        public void UpdateAlarmEvent(List<EventItem> evItems)
        {
            var alarmEvents = new List<AlarmItem>();
            foreach (EventItem item in evItems)
            {
                    var it = new AlarmItem()
                    {
                        Level = item.Level,
                        OccuringTime = item.OccuringTime.ToString("yyyy/MM/dd HH:mm:ss"),
                        Source = item.Source,
                        Description = item.Description,
                        EventEnum = item.EventEnum,
                        EventId = item.Id,
                        Explaination = item.Explaination,
                        Solution = item.Solution,
                    };
                    
                    alarmEvents.Add(it);
            }
            if (AlarmEvents == null || (alarmEvents.Count != AlarmEvents.Count))
            {
                AlarmEvents = alarmEvents;
            }
            else
            {
                bool isEqual = true;
                if (alarmEvents.Count == AlarmEvents.Count)
                {
                    for (int i = 0; i < alarmEvents.Count; i++)
                    {
                        if (!alarmEvents[i].IsEqualTo(AlarmEvents[i]))
                        {
                            isEqual = false;
                            break;
                        }
                    }
                }
                if (!isEqual)
                    AlarmEvents = alarmEvents;
            }

            InvokePropertyChanged("AlarmEvents");
        }
    }
}
