using Wayne_VaporRecoveryDataCollectorBoard.MessageEntity;
using Wayne_VaporRecoveryDataCollectorBoard.MessageEntity.Incoming;
using Edge.Core.Parser.BinaryParser;
using Edge.Core.Parser.BinaryParser.MessageEntity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Wayne_VaporRecoveryDataCollectorBoard
{
    public class MessageTemplateLookup : IMessageTemplateLookup
    {
        const byte MsgStart = 0x68;
        const byte MsgTail = 0x16;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="bytes">msg starter should has been excluded here, so it's: 采集器地址Addr(1B)+命令代码(1B)+数据域长度(1B)+数据域(由数据域长度指定)+校验CS(1B)+包结束标志(1B)。</param>
        /// <returns></returns>
        public MessageTemplateBase GetMessageTemplateByRawBytes(byte[] bytes)
        {
            if (bytes[1] == 0x00 && bytes[2] == 0x00)
                return new COLLECTOR_BUSY_Response();
            else if (bytes[1] == 0x01)
                return new READ_WORKING_AND_TYPE_Response();
            else if (bytes[1] == 0x03)
                return new READ_ONE_HISTORY_DATA_Response();
            else if (bytes[1] == 0x05)
                return new READ_TIME_Response();
            else if (bytes[1] == 0x06)
                return new READ_PARA_Response();
            else if (bytes[1] == 0x07)
                return new READ_HISTORY_NUM_Response();
            else if (bytes[1] == 0x09)
                return new CLEAR_ONE_HISTORY_Response();
            else if (bytes[1] == 0x80)
                return new CLEAR_ONE_HISTORY_Response();
            else if (bytes[1] == 0x81)
                return new WRITE_TIME_Response();
            else if (bytes[1] == 0x82)
                return new WRITE_PARA_Response();
            else if (bytes[1] == 0x83)
                return new WRITE_SWITCH_OUT_Response();
            else if (bytes[1] == 0xA1)
                return new SET_ADDRESS_Response();
            return null;
        }
    }
}