using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NIDAQmx
{
    public class DO : BaseDevice
    {
        internal DO(DAQmxSession session, string deviceName) : base(session, deviceName)
        {
            Lines = GetLines();
            Ports = GetPorts();
            _Session.CheckResult(_Session.GetDelegate<Internal.Internal.DAQmxGetDevDIMaxRate>()(DeviceName, ref maxrate));
        }
        private string[] GetLines()
        {
            byte[] bytes = new byte[1024];
            _Session.CheckResult(_Session.GetDelegate<Internal.Internal.DAQmxGetDevDOLines>()(DeviceName, ref bytes[0], (uint)bytes.Length));
            return System.Text.Encoding.UTF8.GetString(bytes).Trim('\0').Split(',').Select(x => x.Trim('\0')).Where(x => !string.IsNullOrEmpty(x)).ToArray();
        }
        private string[] GetPorts()
        {
            byte[] bytes = new byte[1024];
            _Session.CheckResult(_Session.GetDelegate<Internal.Internal.DAQmxGetDevDOPorts>()(DeviceName, ref bytes[0], (uint)bytes.Length));
            return System.Text.Encoding.UTF8.GetString(bytes).Trim('\0').Split(',').Select(x => x.Trim('\0')).Where(x => !string.IsNullOrEmpty(x)).ToArray();
        }
        private double maxrate;
        public string[] Lines { get; }
        public string[] Ports { get; }
        public double MaxRate => maxrate;
    }
}
