using Aitex.Core.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MECF.Framework.Common.TwinCat
{
    public class BeckhoffItemManager : Singleton<BeckhoffItemManager>
    {

        private Dictionary<string, BeckhoffItem> _ioItemMap = new Dictionary<string, BeckhoffItem>();

        private Dictionary<string, BeckhoffItem> _writeItemMap = new Dictionary<string, BeckhoffItem>();

        public BeckhoffItem GetIOBeckhoffItem(string name)
        {
            return _ioItemMap.ContainsKey(name) ? _ioItemMap[name] : null;
        }

        public BeckhoffItem GetWriteBeckhoffItem(string name)
        {
            return _writeItemMap.ContainsKey(name) ? _writeItemMap[name]: null;
        }
        public void InitBeckhoffItem(string name,string address,string dataType,string scaling,string ioType,int size,bool bitOperated,int bit,bool invert)
        {
            _ioItemMap[name] = new BeckhoffItem(name,address, dataType,scaling, ioType, size,bitOperated,bit,invert);
            ScalingManager.Instance.Initialize(name, scaling);
        }
        public void InitBeckhoffItem(string name, string address, string dataType, string ioType, int size, bool bitOperated, int bit,bool invert)
        {
            _ioItemMap[name] = new BeckhoffItem(name, address, dataType, ioType, size,bitOperated,bit,invert);
        }

        public void InitWriteBeckoffItem(string name, string address, string dataType, string scaling,string ioType, int size, bool bitOperated, int bit,bool invert)
        {
            _writeItemMap[name]=new BeckhoffItem(name,address, dataType,scaling, ioType, size,bitOperated,bit,invert);
            ScalingManager.Instance.Initialize(name, scaling);
        }
        public void InitWriteBeckoffItem(string name, string address, string dataType, string ioType, int size, bool bitOperated, int bit,bool invert)
        {
            _writeItemMap[name] = new BeckhoffItem(name, address, dataType, ioType, size, bitOperated, bit,invert);
        }
        public List<BeckhoffItem> GetIOItems()
        {
            return _ioItemMap.Values.ToList();
        }
        public List<BeckhoffItem> GetWriteItems()
        {
            return _writeItemMap.Values.ToList();
        }
    }
}