using Aitex.Core.RT.Device;
using Aitex.Core.RT.Device.Devices;
using System.Collections.Generic;

namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.OffsetManage
{
    public class OffsetManager
    {
        private List<IoPTOffsetAndK> ioPTOffsetAndKs = new List<IoPTOffsetAndK>();
        private string module;

        public OffsetManager(string _moduleName)
        {
            module = _moduleName;
            IniioPTOffsetAndKs();
        }

        private void IniioPTOffsetAndKs()
        {
            for (int i = 1; i < 5; i++)
            {
                ioPTOffsetAndKs.Add(DEVICE.GetDevice<IoPTOffsetAndK>($"{module}.PT{i}_Offset"));
                ioPTOffsetAndKs.Add(DEVICE.GetDevice<IoPTOffsetAndK>($"{module}.PT{i}_K"));
            }
            ioPTOffsetAndKs.Add(DEVICE.GetDevice<IoPTOffsetAndK>($"{module}.PT9_Offset"));
            ioPTOffsetAndKs.Add(DEVICE.GetDevice<IoPTOffsetAndK>($"{module}.PT9_K"));
            ioPTOffsetAndKs.Add(DEVICE.GetDevice<IoPTOffsetAndK>($"{module}.PT10_Offset"));
            ioPTOffsetAndKs.Add(DEVICE.GetDevice<IoPTOffsetAndK>($"{module}.PT10_K"));

            for (int i = 1; i < 15; i++)
            {
                ioPTOffsetAndKs.Add(DEVICE.GetDevice<IoPTOffsetAndK>($"{module}.U{i}_Water"));
            }
        }

        public void Set()
        {
            if (ioPTOffsetAndKs == null)
                return;
            foreach (IoPTOffsetAndK item in ioPTOffsetAndKs)
            {
                item.Set_Callback();
            }
        }
    }
}