using SWRIS.Enums;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;

namespace SWRIS.Models
{
    public class DataCenterModel : INotifyPropertyChanged
    {
        public DataCenterModel(List<EquipmentModel> equipments, List<LimitData> limits)
        {
            if (equipments != null)
            {
                equipments = equipments.OrderBy(c => c.RopeNumber).ToList();
                foreach (var equipment in equipments)
                {
                    var equipmentData = new EquipmentDataModel()
                    {
                        RopeNumber = equipment.RopeNumber,
                        RopeName = equipment.RopeName,
                        IpAddress = equipment.IpAddress,
                        SerialNo = equipment.SerialNo,
                        SensorCount = equipment.Parameter.SensorCount,
                        SamplingStep = equipment.Parameter.SamplingStep,
                        RopeLength = equipment.Parameter.WireRopeLength,
                        LiftHightRatio = equipment.LiftHightRatio,
                        DisableAlarm = equipment.DisableAlarm,
                        VariationThreshold = App.Config.SpeedVariationThreshold
                    };
                    limits?.ForEach(limit =>
                    {
                        if (limit.RelatedRopes.Contains(equipment.RopeNumber))
                        {
                            equipmentData.Limits.Add(new LimitModel { Name = limit.Name, State = LimitState.Offline, IsEnable = limit.IsEnable });
                        }
                    });
                    Equipments.Add(equipmentData);
                }
            }
        }
        public ObservableCollection<EquipmentDataModel> Equipments { get; set; } = new ObservableCollection<EquipmentDataModel>();

        public event PropertyChangedEventHandler PropertyChanged;
        protected internal virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
