using CommunityToolkit.Mvvm.ComponentModel;
using MegaRobo.Entities;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace Common.DevicesModels
{
    public class PropertyItem : ObservableObject
    {
        private object _value;
        public object Value
        {
            get => _value;
            set
            {
                if (SetProperty(ref _value, value)) // SetProperty 会触发 PropertyChanged
                {
                    // 值变化时，更新 SuckFluidProp 对应属性
                    PropertyInfo?.SetValue(TargetObject, Convert.ChangeType(value, Type));
                }
            }
        }

        // 其他属性（保持不变）
        public string Name { get; set; }
        public string Description { get; set; }
        
        public Type Type { get; set; }
        public NumericAttribute NumericAttribute { get; set; }
        public object TargetObject { get; set; }
        public PropertyInfo PropertyInfo { get; set; }

        //// 通知属性变化
        //public event PropertyChangedEventHandler PropertyChanged;
        //protected void OnPropertyChanged([CallerMemberName] string propName = null)
        //{
        //    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
        //}
    }
}
