using Aitex.Core.RT.Device;
using Aitex.Core.RT.SCCore;
using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Breakers.NSXCOM;
using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.UPS;
using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Temps;

namespace SicRT.Instances
{
    public class DeviceEntity : DeviceEntityT<DeviceManager>
    {
        public DeviceEntity()
        {
        }
    }

    public class DeviceManager : DeviceManagerBase
    {
        public DeviceManager()
        {
        }

        public override bool Initialize()
        {
            //if (SC.GetConfigItem("AETemp.EnableDevice").BoolValue)
            //{
            //    string _address = SC.GetStringValue("AETemp.Address");
            //    bool _enableLog = SC.GetValue<bool>("AETemp.EnableLogMessage");

            //    var aeTemp = new AETemp("PM", "AETemp", "AETemp");
            //    aeTemp.Initialize(_address, _enableLog);
            //    QueueDevice(aeTemp);
            //}
            
            if (SC.GetConfigItem("NSXBreakerII.EnableDevice").BoolValue)
            {
                var NSX = new NSXBreakerII("TM", "NSXBreakerII", "NSXBreakerII");
                NSX.Initialize();
            }

            if (SC.GetConfigItem("PM.PM1.ITAUPSA.EnableDevice").BoolValue)
            {
                var ITPM1A = new ITAUPS("PM1", "ITAUPSA", "ITAUPSA");
                ITPM1A.Initialize();
                QueueDevice(ITPM1A);
            }

            if (SC.GetConfigItem("PM.PM1.ITAUPSB.EnableDevice").BoolValue)
            {
                var ITPM1B = new ITAUPS("PM1", "ITAUPSB", "ITAUPSB");
                ITPM1B.Initialize();
                QueueDevice(ITPM1B);
            }

            if (SC.GetConfigItem("PM.PM2.ITAUPSA.EnableDevice").BoolValue)
            {
                var ITPM2A = new ITAUPS("PM2", "ITAUPSA", "ITAUPSA");
                ITPM2A.Initialize();
                QueueDevice(ITPM2A);
            }

            if (SC.GetConfigItem("PM.PM2.ITAUPSB.EnableDevice").BoolValue)
            {
                var ITPM2B = new ITAUPS("PM2", "ITAUPSB", "ITAUPSB");
                ITPM2B.Initialize();
                QueueDevice(ITPM2B);
            }

            if (SC.GetConfigItem("PM.PM1.EATONUPS.EnableDevice").BoolValue)
            {
                var EATONUPS1 = new EATONUPS("PM1", "EATONUPS", "EATONUPS");
                EATONUPS1.Initialize();
                QueueDevice(EATONUPS1);
            }

            if (SC.GetConfigItem("PM.PM2.EATONUPS.EnableDevice").BoolValue)
            {
                var EATONUPS2 = new EATONUPS("PM2", "EATONUPS", "EATONUPS");
                EATONUPS2.Initialize();
                QueueDevice(EATONUPS2);
            }

            //if (SC.GetConfigItem("AKunTemp.EnableDevice").BoolValue)
            //{
            //    var AkOptics = new AKunTemp("PM1", "AKunTemp");
            //    AkOptics.Initialize();
            //    QueueDevice(AkOptics);
            //}

            return true;
        }

        protected override void QueueDevice(IDevice device)
        {
            QueueDevice($"{device.Module}.{device.Name}", device);
        }

    }
}