using NEIntelligentControl2.Models.Datas;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NEIntelligentControl2.Models.PV
{
    /// <summary>
    /// 光伏SUN2000信息
    /// </summary>
    public class SUN2000Info
    {
        /// <summary>
        /// 名称
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 电流
        /// </summary>
        public PVTagInfo I { get; set; }
        /// <summary>
        /// 电压
        /// </summary>
        public PVTagInfo V { get; set; }
        /// <summary>
        /// 电流变化值
        /// </summary>
        public double ΔI { get; set; }
        /// <summary>
        /// 功率
        /// </summary>
        public double P
        {
            get
            {
                if (I == null || V == null) return 0.0;
                return I.Value * V.Value / 1000;
            }
        }
        /// <summary>
        /// 值改变
        /// </summary>
        public Action<double, double> ValueChanged { get; set; }

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="vs"></param>
        internal void UpdateValue(Dictionary<string, TsData> vs)
        {
            if (vs == null) return;
            var bi = I.Value;
            V.UpdateValue(vs);
            I.UpdateValue(vs);
            if (bi != I.Value && bi != 0)
            {
                ΔI = Math.Abs(I.Value - bi);
            }
            ValueChanged?.Invoke(P, ΔI);
        }
    }
}
