using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZEISS.MTB.Api;
using YQLInterfaces;
using YQLUtils;
namespace ZeissMicroscopeAPI
{
    public class LampController
    {
        public static int     LampType                (IMicroscope Manager                                                        )
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                result = (int)Manager.LampHandler.LampType;
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static int     LampIsActive            (IMicroscope Manager                                                        )
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                result = Manager.LampHandler.IsActive ? Settings.RECODE_SUCCEED : Settings.RECODE_FAILURE;
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static int     LampLightPathLocation   (IMicroscope Manager                                                        )
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                result = (int)Manager.LampHandler.LightPathLocation;
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static int     LampHasRemote           (IMicroscope Manager                                                        )
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                result = Manager.LampHandler.HasRemote ? Settings.RECODE_SUCCEED : Settings.RECODE_FAILURE;
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static int     LampHasOnOff            (IMicroscope Manager                                                        )
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                result = Manager.LampHandler.HasOnOff ? Settings.RECODE_SUCCEED : Settings.RECODE_FAILURE;
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static int     LampHas3200K            (IMicroscope Manager                                                        )
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                result = Manager.LampHandler.Has3200K ? Settings.RECODE_SUCCEED : Settings.RECODE_FAILURE;
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static int     LampGet3200K            (IMicroscope Manager                                                        )
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                result = Manager.LampHandler.Get3200K() == MTBOnOff.On ? Settings.RECODE_SUCCEED : Settings.RECODE_FAILURE;
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static int     LampGetOnOff            (IMicroscope Manager                                                        )
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                result = Manager.LampHandler.GetOnOff() == MTBOnOff.On ? Settings.RECODE_SUCCEED : Settings.RECODE_FAILURE;
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static int     LampGetRemote           (IMicroscope Manager                                                        )
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                result = Manager.LampHandler.GetRemote() == MTBOnOff.On ? Settings.RECODE_SUCCEED : Settings.RECODE_FAILURE;
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static int     LampSetRemote           (IMicroscope Manager , bool     onOff                                       )
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                Manager.LampHandler.SetRemote(onOff ? MTBOnOff.On : MTBOnOff.Off);
                result = Settings.RECODE_SUCCEED;
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static int     LampSet3200K            (IMicroscope Manager , bool     onOff       , int mode                      )
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                Manager.LampHandler.Set3200K(onOff ? MTBOnOff.On : MTBOnOff.Off, (MTBCmdSetModes)mode);
                result = Settings.RECODE_SUCCEED;
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static int     LampSetOnOff            (IMicroscope Manager , bool     onOff       , int mode                      )
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                Manager.LampHandler.SetOnOff(onOff ? MTBOnOff.On : MTBOnOff.Off, (MTBCmdSetModes)mode);
                result = Settings.RECODE_SUCCEED;
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static int     LampSet3200K            (IMicroscope Manager , bool     onOff       , int mode      , int timeout   )
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                Manager.LampHandler.Set3200K(onOff ? MTBOnOff.On : MTBOnOff.Off, (MTBCmdSetModes)mode, timeout);
                result = Settings.RECODE_SUCCEED;
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static int     LampSetOnOff            (IMicroscope Manager , bool     onOff       , int mode      , int timeout   )
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                Manager.LampHandler.SetOnOff(onOff ? MTBOnOff.On : MTBOnOff.Off, (MTBCmdSetModes)mode, timeout);
                result = Settings.RECODE_SUCCEED;
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static int     LampIsOnHWLimit         (IMicroscope Manager)
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                var limit = Manager.LampHandler.IsOnHWLimit;
                switch(limit)
                {
                    case MTBLimits.None:
                        result = Settings.RECODE_FAILURE;
                        break;
                    case MTBLimits.Lower:
                        result = Settings.RECODE_SUCCEED;
                        break;
                    case MTBLimits.Upper:
                        result = Settings.RECODE_WARNING;
                        break;
                    default:
                        result = Settings.RECODE_FAILURE;
                        break;
                }
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static double  LampGetMaxPosition      (IMicroscope Manager                                                        )
        {
            var result = Settings.DEFAULT_DOUBLE;
            try
            {
                result = Manager.LampHandler.GetMaxPosition(Manager.MTBUnit);
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static double  LampGetMinPosition      (IMicroscope Manager                                                        )
        {
            var result = Settings.DEFAULT_DOUBLE;
            try
            {
                result = Manager.LampHandler.GetMinPosition(Manager.MTBUnit);
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static double  LampGetPosition         (IMicroscope Manager                                                        )
        {
            var result = Settings.DEFAULT_DOUBLE;
            try
            {
                result = Manager.LampHandler.GetPosition(Manager.MTBUnit);
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static int     LampGetPositionUnitCount(IMicroscope Manager                                                        )
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                result = Manager.LampHandler.GetPositionUnitCount();
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static double  LampGetTargetPosition   (IMicroscope Manager                                                        )
        {
            var result = Settings.DEFAULT_DOUBLE;
            try
            {
                result = Manager.LampHandler.GetTargetPosition(Manager.MTBUnit);
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static double  LampMaxDeviation        (IMicroscope Manager                                                        )
        {
            var result = Settings.DEFAULT_DOUBLE;
            try
            {
                result = Manager.LampHandler.MaxDeviation(Manager.MTBUnit);
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static double  LampStepWidth           (IMicroscope Manager                                                        )
        {
            var result = Settings.DEFAULT_DOUBLE;
            try
            {
                result = Manager.LampHandler.StepWidth(Manager.MTBUnit);
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static double  LampTypicalDeviation    (IMicroscope Manager                                                        )
        {
            var result = Settings.DEFAULT_DOUBLE;
            try
            {
                result = Manager.LampHandler.TypicalDeviation(Manager.MTBUnit);
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static string  LampGetPositionUnit     (IMicroscope Manager , int      index                                       )
        {
            var result = Settings.DEFAULT_STRING;
            try
            {
                result = Manager.LampHandler.GetPositionUnit(index);
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static int    LampSetPosition         (IMicroscope Manager , double   position    , int mode                      )
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                Manager.LampHandler.SetPosition(position, Manager.MTBUnit, (MTBCmdSetModes)mode);
                result = Settings.RECODE_SUCCEED;
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static int    LampSetPosition         (IMicroscope Manager , double   position    , int mode      , int timeout)
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                Manager.LampHandler.SetPosition(position, Manager.MTBUnit, (MTBCmdSetModes)mode, timeout);
                result = Settings.RECODE_SUCCEED;
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static int     LampIsMonitoring            (IMicroscope Manager                                                        )
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                result = Manager.LampHandler.IsMonitoring ? Settings.RECODE_SUCCEED : Settings.RECODE_FAILURE;
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static int     LampIsLocked                (IMicroscope Manager                                                        )
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                result = Manager.LampHandler.IsLocked ? Settings.RECODE_SUCCEED : Settings.RECODE_FAILURE;
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static int     LampIsBusy                  (IMicroscope Manager                                                        )
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                result = Manager.LampHandler.IsBusy ? Settings.RECODE_SUCCEED : Settings.RECODE_FAILURE;
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static int     LampHasMonitoring           (IMicroscope Manager                                                        )
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                result = Manager.LampHandler.HasMonitoring ? Settings.RECODE_SUCCEED : Settings.RECODE_FAILURE;
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static int     LampIsLockedForClient       (IMicroscope Manager                                                        )
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                result = Manager.LampHandler.IsLockedForClient(Manager.MicroscopeID) ? Settings.RECODE_SUCCEED : Settings.RECODE_FAILURE;
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static int     LampIsMonitoringForClient   (IMicroscope Manager                                                        )
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                result = Manager.LampHandler.IsMonitoringForClient(Manager.MicroscopeID) ? Settings.RECODE_SUCCEED : Settings.RECODE_FAILURE;
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static int     LampLock                    (IMicroscope Manager                                                        )
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                result = Manager.LampHandler.Lock(Manager.MicroscopeID) ? Settings.RECODE_SUCCEED : Settings.RECODE_FAILURE;
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static int     LampStartMonitoring         (IMicroscope Manager                                                        )
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                result = Manager.LampHandler.StartMonitoring(Manager.MicroscopeID) ? Settings.RECODE_SUCCEED : Settings.RECODE_FAILURE;
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static int     LampStopMonitoring          (IMicroscope Manager                                                        )
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                result = Manager.LampHandler.StopMonitoring(Manager.MicroscopeID) ? Settings.RECODE_SUCCEED : Settings.RECODE_FAILURE;
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static int     LampUnlock                  (IMicroscope Manager                                                        )
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                result = Manager.LampHandler.Unlock(Manager.MicroscopeID) ? Settings.RECODE_SUCCEED : Settings.RECODE_FAILURE;
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static int LampWaitReady               (IMicroscope Manager, int timeout                                           )
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                result = Manager.LampHandler.WaitReady(timeout) ? Settings.RECODE_SUCCEED : Settings.RECODE_FAILURE;
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static int SetLampILTLSwitch(IMicroscope Manager, bool enable, int mode)
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                int ENABLE = enable ? 1 : 0;
                result = Manager.MTBRLTLSwitch.SetPosition((short)ENABLE, (MTBCmdSetModes)mode) ? Settings.RECODE_SUCCEED : Settings.RECODE_FAILURE;
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
        public static int GetLampILTLSwitch(IMicroscope Manager)
        {
            var result = Settings.RECODE_FAILURE;
            try
            {
                result = Convert.ToInt32(Manager.MTBRLTLSwitch.Position);
            }
            catch (Exception E) { YQLUtil.Print_Exception(E); }
            return result;
        }
    }
}
