using System;
using System.Collections.Generic;
using System.IO.Ports;
using ChuPiao.AutoPrint.Machine.Models;
using ChuPiao.Common.Enums;
using ChuPiao.Common.Models;
using log4net;

namespace ChuPiao.AutoPrint.Machine
{
    public abstract class BaseVirtualKeyboard:IVirtualKeyboard
    {
        #region Implementation of IVirtualKeyboard

        private VirtualKeyboardStatus _status;

        private ILog _log;

        private SerialPort _keyboardPort;

        private KeyboardType _keyboardType;

        private M_MachineEntity _machineInfo;

        private string _port;

        private int _portBps;

        private bool _isSend = false;

        private SortedDictionary<string, M_KeycodeConfigEntity> _keycodeDictionary;

        private KeycodeInfo _clearScreenSaverKeycode;

        private Queue<KeycodeInfo> _waitSendKeycodeQueue;

        /// <summary>
        /// 键盘状态
        /// </summary>
        public VirtualKeyboardStatus Status
        {
            get { return _status; }
            set { _status=value; }
        }

        /// <summary>
        /// 日志记录器
        /// </summary>
        public ILog Log
        {
            get { return _log; }
            set { _log = value; }
        }

        /// <summary>
        /// 端口
        /// </summary>
        public SerialPort KeyboardPort
        {
            get { return _keyboardPort; }
            set { _keyboardPort = value; }
        }

        /// <summary>
        /// 键盘类型
        /// </summary>
        public KeyboardType KeyboardType
        {
            get { return _keyboardType; }
            set { _keyboardType = value; }
        }

        /// <summary>
        /// 键码词典
        /// </summary>
        public SortedDictionary<string, M_KeycodeConfigEntity> KeycodeDictionary
        {
            get { return _keycodeDictionary; }
            set { _keycodeDictionary = value; }
        }

        /// <summary>
        /// 屏保清除键
        /// </summary>
        public KeycodeInfo ClearScreenSaverKeycode
        {
            get { return _clearScreenSaverKeycode; }
            set { _clearScreenSaverKeycode=value; }
        }

        /// <summary>
        /// 等待发送的键码队列
        /// </summary>
        public Queue<KeycodeInfo> WaitSendKeycodeQueue
        {
            get { return _waitSendKeycodeQueue; }
            set { _waitSendKeycodeQueue=value; }
        }

        /// <summary>
        /// 彩票机相关信息
        /// </summary>
        public M_MachineEntity MachineInfo
        {
            get { return _machineInfo; }
            set { _machineInfo = value; }
        }

        /// <summary>
        /// 端口号
        /// </summary>
        public string Port
        {
            get { return _port; }
            set { _port = value; }
        }

        /// <summary>
        /// 端口波特率
        /// </summary>
        public int PortBps
        {
            get { return _portBps; }
            set { _portBps = value; }
        }
        /// <summary>
        /// 是否发送
        /// </summary>
        public bool IsSend
        {
            get { return _isSend; }
            set { _isSend = value; }
        }

        /// <summary>
        /// 初始化
        /// </summary>
        public abstract void Initialize();

        /// <summary>
        /// 启动
        /// </summary>
        public abstract void Start();

        /// <summary>
        /// 停止
        /// </summary>
        public abstract void Stop();

        /// <summary>
        /// 输入键码
        /// </summary>
        public abstract void Input(List<KeycodeInfo> keycodeInfo);

        #endregion

        #region 属性
        #endregion
    }
}
