using SWRIS.Dtos;
using System.Collections.ObjectModel;
using System.ComponentModel;

namespace SWRIS.Models.ViewModel
{
    public class DamagesViewModel : INotifyPropertyChanged
    {
        private RecordDto _record;
        private ObservableCollection<SensorModel> _sensors;
        private bool _isSummaryActive = true;
        public RecordDto Record
        {
            get => _record;
            set
            {
                if (_record != value)
                {
                    _record = value;
                    OnPropertyChanged(nameof(Record));
                }
            }
        }
        public ObservableCollection<SensorModel> Sensors
        {
            get => _sensors;
            set
            {
                if (_sensors != value)
                {
                    _sensors = value;
                    OnPropertyChanged(nameof(Sensors));
                }
            }
        }
        public bool IsSummaryActive
        {
            get => _isSummaryActive;
            set
            {
                if (_isSummaryActive != value)
                {
                    _isSummaryActive = value;
                    OnPropertyChanged(nameof(IsSummaryActive));

                    // 如果合值被选中，取消所有传感器的选中状态
                    if (_isSummaryActive)
                    {
                        foreach (var sensor in Sensors)
                        {
                            sensor.IsActive = false;
                        }
                    }
                }
            }
        }

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