using Aitex.Core.RT.DataCenter;
using Aitex.Core.RT.IOCore;
using MECF.Framework.Common.Aitex.Core.Common.DeviceData;
using System.Xml;

namespace Aitex.Core.RT.Device.Devices
{
    public class IoConcentration : BaseDevice, IDevice
    {
        protected readonly AIAccessor _aiTCSConcentration;

        protected readonly AIAccessor _aiTCSPressure;

        protected readonly AIAccessor _aiTCSTemp;

        private AIConcentrationData _aiConcentration;

        private AIConcentrationData AIConcentration
        {
            get 
            {
                _aiConcentration.Concentration = _aiTCSConcentration.Value;
                _aiConcentration.Pressure = _aiTCSPressure.Value;
                _aiConcentration.Temp = _aiTCSTemp.Value;

                return _aiConcentration;
            }
        }

        public IoConcentration(string module, XmlElement node, string ioModule = "") : base(module, node, ioModule)
        {
            _aiTCSConcentration = ParseAiNode("aiTCSConcentration", node, ioModule);
            _aiTCSPressure = ParseAiNode("aiTCSPressure", node, ioModule);
            _aiTCSTemp = ParseAiNode("aiTCSTemp", node, ioModule);

            _aiConcentration = new();
        }

        public bool Initialize()
        {
            DATA.Subscribe($"{Module}.{Name}.ConcentrationData", () => AIConcentration);
            return true;
        }

        public void Reset()
        {
            
        }

        public void Terminate()
        {
            
        }
    }
}
