using NIDAQmx.DAQmxEnum;
using NIDAQmxConst;
using System;
using System.Collections.Generic;
using System.Diagnostics.SymbolStore;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace NIDAQmx
{
    public class Read : DAQmxBase
    {

        internal Read(DAQmxSession session) : base(session)
        {
            Logging = new Logging(session);
            Status = new Status(session);
        }
        public Logging Logging { get; }
        public Status Status { get; }
        public ReadRelativeTo RelativeTo 
        {
            get
            {
                ReadRelativeTo read = ReadRelativeTo.RefTrig;
                _Session.CheckResult(_Session.GetDelegate<Internal.Read.DAQmxGetReadRelativeTo>()(_Session.TaskHandle, ref read));
                return read;
            }
            set
            {
                _Session.CheckResult(_Session.GetDelegate<Internal.Read.DAQmxSetReadRelativeTo>()(_Session.TaskHandle, value));
            }
        }
        public int Offset
        {
            get
            {
                int val = 0;
                _Session.CheckResult(_Session.GetDelegate<Internal.Read.DAQmxGetReadOffset>()(_Session.TaskHandle, ref val));
                return val;
            }
            set
            {
                _Session.CheckResult(_Session.GetDelegate<Internal.Read.DAQmxSetReadOffset>()(_Session.TaskHandle, value));
            }
        }
        public string ChannelsToRead 
        {
            get
            {
                byte[] bytes = new byte[1024];
                _Session.CheckResult(_Session.GetDelegate<Internal.Read.DAQmxGetReadChannelsToRead>()(_Session.TaskHandle, ref bytes[0], (uint)bytes.Length));
                return System.Text.Encoding.UTF8.GetString(bytes).Trim('\0');
            }
            set
            {
                _Session.CheckResult(_Session.GetDelegate<Internal.Read.DAQmxSetReadChannelsToRead>()(_Session.TaskHandle, value));
            }
        }
        public bool ReadAllAvailSamp
        {
            get
            {
                bool val = false;
                _Session.CheckResult(_Session.GetDelegate<Internal.Read.DAQmxGetReadReadAllAvailSamp>()(_Session.TaskHandle, ref val));
                return val;
            }
            set => _Session.CheckResult(_Session.GetDelegate<Internal.Read.DAQmxSetReadReadAllAvailSamp>()(_Session.TaskHandle,value));
        }
        public bool AutoStart 
        {
            get
            {
                bool val = false;
                _Session.CheckResult(_Session.GetDelegate<Internal.Read.DAQmxGetReadAutoStart>()(_Session.TaskHandle, ref val));
                return val;
            }
            set =>_Session.CheckResult(_Session.GetDelegate<Internal.Read.DAQmxSetReadAutoStart>()(_Session.TaskHandle,value));
        }
        public ReadOverWrite OverWrite 
        {
            get
            {
                ReadOverWrite val =  ReadOverWrite.DoNotOverwriteUnreadSamps;
                _Session.CheckResult(_Session.GetDelegate<Internal.Read.DAQmxGetReadOverWrite>()(_Session.TaskHandle, ref val));
                return val;
            }
            set => _Session.CheckResult(_Session.GetDelegate<Internal.Read.DAQmxSetReadOverWrite>()(_Session.TaskHandle,value));
        }

    }
    public class Logging
    {
        private DAQmxSession _Session;
        internal Logging(NIDAQmx.DAQmxSession session)
        {
            _Session = session;
        }
        public string FilePath { get => _Session.GetValue<Internal.Read.DAQmxGetLoggingFilePath>();set=>_Session.SetValue<Internal.Read.DAQmxSetLoggingFilePath>(value); }
        public LoggingMode LoggingMode { get => _Session.GetValue<Internal.Read.DAQmxGetLoggingMode,LoggingMode>();set=>_Session.SetValue<Internal.Read.DAQmxSetLoggingMode,LoggingMode>(value); }
        public string TDMSGroupName { get => _Session.GetValue<Internal.Read.DAQmxGetLoggingTDMSGroupName>();set=>_Session.SetValue<Internal.Read.DAQmxSetLoggingTDMSGroupName>(value); } 
        public LoggingOperation TDMSOperation { get => _Session.GetValue<Internal.Read.DAQmxGetLoggingTDMSOperation,LoggingOperation>();set=>_Session.SetValue<Internal.Read.DAQmxSetLoggingTDMSOperation,LoggingOperation>(value); } 
        public bool Pause { get => _Session.GetValue<Internal.Read.DAQmxGetLoggingPause,bool>(); set => _Session.SetValue<Internal.Read.DAQmxSetLoggingPause,bool>(value); }
        public ulong SampsPerFile { get => _Session.GetValue<Internal.Read.DAQmxGetLoggingSampsPerFile,ulong>(); set => _Session.SetValue<Internal.Read.DAQmxSetLoggingSampsPerFile,ulong>(value); }
        public uint FileWriteSize { get => _Session.GetValue<Internal.Read.DAQmxGetLoggingFileWriteSize,uint>(); set => _Session.SetValue<Internal.Read.DAQmxSetLoggingFileWriteSize,uint>(value); }
        public ulong FilePreallocationSize { get => _Session.GetValue<Internal.Read.DAQmxGetLoggingFilePreallocationSize,ulong>(); set => _Session.SetValue<Internal.Read.DAQmxSetLoggingFilePreallocationSize,ulong>(value); }
    }

    public class Status
    {
        DAQmxSession _Session;
        internal Status(NIDAQmx.DAQmxSession session) 
        {
            _Session = session;
        }
        public ulong CurrReadPos => _Session.GetValue<Internal.Read.DAQmxGetReadCurrReadPos, ulong>();
        public uint AvailSampPerChan => _Session.GetValue<Internal.Read.DAQmxGetReadAvailSampPerChan,uint>();
        public ulong TotalSampPerChanAcquired => _Session.GetValue<Internal.Read.DAQmxGetReadTotalSampPerChanAcquired,ulong>();
        public bool CommonModeRangeErrorChansExist=>_Session.GetValue<Internal.Read.DAQmxGetReadCommonModeRangeErrorChansExist,bool>();
        public string CommonModeRangeErrorChans => _Session.GetValue<Internal.Read.DAQmxGetReadCommonModeRangeErrorChans>();
        public bool ExcitFaultChansExist => _Session.GetValue<Internal.Read.DAQmxGetReadExcitFaultChansExist, bool>();
        public string ExcitFaultChans=>_Session.GetValue<Internal.Read.DAQmxGetReadExcitFaultChans>();
        public bool OvercurrentChansExist => _Session.GetValue<Internal.Read.DAQmxGetReadOvercurrentChansExist,bool>();
        public string OvercurrentChans => _Session.GetValue<Internal.Read.DAQmxGetReadOverloadedChans>();
        public bool OvertemperatureChansExist => _Session.GetValue<Internal.Read.DAQmxGetReadOvertemperatureChansExist,bool>();
        public string OvertemperatureChans => _Session.GetValue<Internal.Read.DAQmxGetReadOvertemperatureChans>();
        public bool OpenChansExist => _Session.GetValue<Internal.Read.DAQmxGetReadOpenChansExist,bool>();
        public string OpenChans => _Session.GetValue<Internal.Read.DAQmxGetReadOpenChans>();
        public string OpenChansDetails=>_Session.GetValue<Internal.Read.DAQmxGetReadOpenChansDetails>();
        public bool OpenCurrentLoopChansExist => _Session.GetValue<Internal.Read.DAQmxGetReadOpenCurrentLoopChansExist,bool>();
        public string OpenCurrentLoopChans => _Session.GetValue<Internal.Read.DAQmxGetReadOpenCurrentLoopChans>();
        public bool OpenThrmcplChansExist => _Session.GetValue<Internal.Read.DAQmxGetReadOpenThrmcplChansExist,bool>();
        public string OpenThrmcplChans => _Session.GetValue<Internal.Read.DAQmxGetReadOpenThrmcplChans>();

        public bool OverloadedChansExist => _Session.GetValue<Internal.Read.DAQmxGetReadOverloadedChansExist,bool>();
        public string OverloadedChans => _Session.GetValue<Internal.Read.DAQmxGetReadOverloadedChans>();
        public bool InputLimitsFaultChansExist => _Session.GetValue<Internal.Read.DAQmxGetReadInputLimitsFaultChansExist,bool>();
        public string InputLimitsFaultChans => _Session.GetValue<Internal.Read.DAQmxGetReadInputLimitsFaultChans>();
        public bool PLL_UnlockedChansExist => _Session.GetValue<Internal.Read.DAQmxGetReadPLLUnlockedChansExist,bool>();
        public string PLL_UnlockedChans => _Session.GetValue<Internal.Read.DAQmxGetReadPLLUnlockedChans>();
        public bool PowerSupplyFaultChansExist => _Session.GetValue<Internal.Read.DAQmxGetReadPowerSupplyFaultChansExist,bool>();
        public string PowerSupplyFaultChans => _Session.GetValue<Internal.Read.DAQmxGetReadPowerSupplyFaultChans>();
        public bool Sync_UnlockedChansExist => _Session.GetValue<Internal.Read.DAQmxGetReadSyncUnlockedChansExist,bool>();
        public string Sync_UnlockedChans=>_Session.GetValue<Internal.Read.DAQmxGetReadSyncUnlockedChans>();
        public bool AccessoryInsertionOrRemovalDetected => _Session.GetValue<Internal.Read.DAQmxGetReadAccessoryInsertionOrRemovalDetected,bool>();
        public string DevsWithInsertedOrRemovedAccessories => _Session.GetValue<Internal.Read.DAQmxGetReadDevsWithInsertedOrRemovedAccessories>();
        public bool ChangeDetect_HasOverflowed => _Session.GetValue<Internal.Read.DAQmxGetReadChangeDetectHasOverflowed,bool>();
        public uint RawDataWidth=>_Session.GetValue<Internal.Read.DAQmxGetReadRawDataWidth,uint>();
        public uint NumChans => _Session.GetValue<Internal.Read.DAQmxGetReadNumChans,uint>();
        public uint DigitalLines_BytesPerChan => _Session.GetValue<Internal.Read.DAQmxGetReadDigitalLinesBytesPerChan,uint>();
        public ReadWaitMode WaitMode { get => _Session.GetValue<Internal.Read.DAQmxGetReadWaitMode,ReadWaitMode>(); set => _Session.SetValue<Internal.Read.DAQmxSetReadWaitMode,ReadWaitMode>(value); }
        public double SleepTime { get => _Session.GetValue<Internal.Read.DAQmxGetReadSleepTime,double>(); set => _Session.SetValue<Internal.Read.DAQmxSetReadSleepTime,double>(value); }
    }
}
