using NIDAQmx.DAQmxEnum;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics.Tracing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NIDAQmx
{
    public class DAQmx
    {
        private DAQmxSession _session;
        private List<Channel> channels= new List<Channel>();
        public Boolean Error=> _session.Error;
        public string Message=>_session.Message;
        List<Device> devices= new List<Device>();
        public IReadOnlyList<Device> Devices=>devices;
        public DAQmx()
        {
            _session = new DAQmxSession();
            Buffer = new Buffer(_session);
            Task = new Task(_session);
            SystemInfo = new SystemInfo(_session);
            Timing = new Timing(_session);
            foreach(var val in SystemInfo.DevNames)
            {
                devices.Add(new Device(_session, val));
            }
            AIChannelFactory = new AIChannelFactory(this);
            AOChannelFactory = new AOChannelFactory(this);
            DIChannelFactory = new DIChannelFactory(this);
            DOChannelFactory = new DOChannelFactory(this);
            CIChannelFactory = new CIChannelFactory(this);
            COChannelFactory = new COChannelFactory(this);
            Read = new Read(_session);
            Write = new Write(_session);
        }
        public AIChannelFactory AIChannelFactory { get; }
        public AOChannelFactory AOChannelFactory { get; }
        public DIChannelFactory DIChannelFactory { get; }
        public DOChannelFactory DOChannelFactory { get; }
        public CIChannelFactory CIChannelFactory { get; }
        public COChannelFactory COChannelFactory { get; }
        public ChannelConfig GetChannelConfig(string activeChs)
        {
            ChannelConfig config = new ChannelConfig(_session);
            config.ActiveChans = activeChs;
            return config;
        }
        internal void RemoveChannel(Channel channel)=>channels.Remove(channel);
        internal void AddChannel(Channel channel)=>channels.Add(channel);
        internal DAQmxSession Session => _session;
        public Buffer Buffer { get; } 
        public Task Task { get; }
        public SystemInfo SystemInfo { get; }
        public Timing Timing { get; }
        public Read Read { get; }
        public Write Write { get; }
        public IReadOnlyList<Channel> Channels=>channels;
    }
}
