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

namespace NIDAQmx
{
    public class Timing : DAQmxBase
    {
        internal Timing(DAQmxSession session) : base(session)
        {
            
        }

        public SampleModes QuantSampMode { get => _Session.GetValue<Internal.Timing.DAQmxGetSampQuantSampMode, SampleModes>(); set => _Session.SetValue<Internal.Timing.DAQmxSetSampQuantSampMode, SampleModes>(value); }

        public string RefClkSource { get => _Session.GetValue<NIDAQmx.Internal.Timing.DAQmxGetRefClkSrc>(); set => _Session.Invoke<Internal.Timing.DAQmxSetRefClkSrc>(_Session.TaskHandle,value); }
        public String SampleClkSource { get => _Session.GetValue<Internal.Timing.DAQmxGetSampClkSrc>(); set => _Session.Invoke<Internal.Timing.DAQmxSetSampClkSrc>(value); }
        public Double SampClkMaxRate => _Session.GetValue<Internal.Timing.DAQmxGetSampClkMaxRate, double>();
        public void CfgSampClkTiming(string source, double rate, AnalogActiveEdge edge, SampleModes sampleMode, UInt64 sampsPerChan)
        {
            _Session.CheckResult(_Session.GetDelegate<Internal.Timing.DAQmxCfgSampClkTiming>()(_Session.TaskHandle, source, rate, edge, sampleMode, sampsPerChan));
            if (_Session.Error)
            {
                throw new Exception("Sample Clock Set Faild");
            }
        }
        public void CfgHandshakingTiming(SampleModes sampleMode,ulong sampsPerChan)
        {
            _Session.CheckResult(_Session.GetDelegate<Internal.Timing.DAQmxCfgHandshakingTiming>()(_Session.TaskHandle, sampleMode, sampsPerChan));
            if (_Session.Error)
            {
                throw new Exception("Sample Clock Set Faild");
            }
        }
        public void CfgBurstHandshakingTimingImportClock(SampleModes sampleMode, ulong sampsPerChan, double sampleClkRate,string sampleClkSrc, AnalogActiveEdge sampleClkActiveEdge, ActiveLevel pauseWhen, ActiveLevel readyEventActiveLevel)
        {
            _Session.CheckResult(_Session.GetDelegate<Internal.Timing.DAQmxCfgBurstHandshakingTimingImportClock>()(_Session.TaskHandle, sampleMode, sampsPerChan,sampleClkRate,sampleClkSrc,sampleClkActiveEdge,pauseWhen,readyEventActiveLevel));
            if (_Session.Error)
            {
                throw new Exception("Sample Clock Set Faild");
            }
        }
        public void CfgBurstHandshakingTimingExportClock(SampleModes sampleMode, ulong sampsPerChan, double sampleClkRate, string sampleClkSrc, AnalogActiveEdge sampleClkActiveEdge, ActiveLevel pauseWhen, ActiveLevel readyEventActiveLevel)
        {
            _Session.CheckResult(_Session.GetDelegate<Internal.Timing.DAQmxCfgBurstHandshakingTimingExportClock>()(_Session.TaskHandle, sampleMode, sampsPerChan, sampleClkRate, sampleClkSrc, sampleClkActiveEdge, pauseWhen, readyEventActiveLevel));
            if (_Session.Error)
            {
                throw new Exception("Sample Clock Set Faild");
            }
        }
        public void CfgChangeDetectionTiming(string risingEdgeChan, string fallingEdgeChan, SampleModes sampleMode, ulong sampsPerChan)
        {
            _Session.CheckResult(_Session.GetDelegate<Internal.Timing.DAQmxCfgChangeDetectionTiming>()(_Session.TaskHandle, risingEdgeChan, fallingEdgeChan, sampleMode, sampsPerChan));
            if (_Session.Error)
            {
                throw new Exception("Sample Clock Set Faild");
            }
        }
        public void CfgImplicitTiming(SampleModes sampleMode, ulong sampsPerChan)
        {
            _Session.CheckResult(_Session.GetDelegate<Internal.Timing.DAQmxCfgImplicitTiming>()(_Session.TaskHandle, sampleMode, sampsPerChan));
            if (_Session.Error)
            {
                throw new Exception("Sample Clock Set Faild");
            }
        }
        public void CfgPipelinedSampClkTiming(string source, double rate, AnalogActiveEdge activeEdge, SampleModes sampleMode, ulong sampsPerChan)
        {
            _Session.CheckResult(_Session.GetDelegate<Internal.Timing.DAQmxCfgPipelinedSampClkTiming>()(_Session.TaskHandle, source, rate,activeEdge,sampleMode,sampsPerChan));
            if (_Session.Error)
            {
                throw new Exception("Sample Clock Set Faild");
            }
        }


        public TimingType SampTimingType { get => _Session.GetValue<Internal.Timing.DAQmxGetSampTimingType, TimingType>(); set => _Session.SetValue<Internal.Timing.DAQmxSetSampTimingType, TimingType>(value); }

        public ulong SampsPerChan
        {
            get => _Session.GetValue<Internal.Timing.DAQmxGetSampQuantSampPerChan,ulong>();
            set => _Session.SetValue<Internal.Timing.DAQmxSetSampQuantSampPerChan,ulong>(value);
        }
        public double SampClkRate
        {
            get => _Session.GetValue<Internal.Timing.DAQmxGetSampClkRate,double>();
            set => _Session.SetValue<Internal.Timing.DAQmxSetSampClkRate,double>(value);
        }
        public AnalogActiveEdge SampClkActiveEdge { get => _Session.GetValue<Internal.Timing.DAQmxGetSampClkActiveEdge,AnalogActiveEdge>(); set => _Session.SetValue<Internal.Timing.DAQmxSetSampClkActiveEdge,AnalogActiveEdge>(value); }
        public string SampClkSrc { get => _Session.GetValue<Internal.Timing.DAQmxGetSampClkSrc>(); set => _Session.SetValue<Internal.Timing.DAQmxSetSampClkSrc>(value); }
        public SampClkOverrunBehavior SampClkOverrunBehavior { get => _Session.GetValue<Internal.Timing.DAQmxGetSampClkOverrunBehavior,SampClkOverrunBehavior>(); set => _Session.SetValue<Internal.Timing.DAQmxSetSampClkOverrunBehavior,SampClkOverrunBehavior>(value); }
    }
}
