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

namespace HengshanPaymentTerminal.MessageEntity.Incoming
{
    /// <summary>
    /// 普通应答格式数据包
    /// </summary>
    public class CommonAnswerBack : CommonMessage
    {
        /// <summary>
        /// 原命令字
        /// </summary>
        public Byte Command { get; set; }

        /// <summary>
        /// 枪号，无枪号填0
        /// </summary>
        public int NozzleNum { get; set; }

        /// <summary>
        /// 应答命令状态
        /// </summary>
        public RESULT Result { get; set; }

        //public override string ToLogString()
        //{
        //    return "";
        //}

        public override CommonMessage ToObject(byte[] datas)
        {
            string v = BitConverter.ToString(datas).Replace("-", " ");
            getBaseData(datas);
            this.Command = datas[7];
            this.NozzleNum = datas[8];
            if (Enum.IsDefined(typeof(RESULT), datas[9]))
            {
                this.Result = (RESULT)datas[9];
            }
            
            return this;
        }

        public override byte[] ToCommonByteArray()
        {
            return new byte[0];
        }
    }

    public enum RESULT:Byte
    {
        /// <summary>
        /// 命令收到，处理完成
        /// </summary>
        OVER = 0x01,

        /// <summary>
        /// 命令收到，在处理，需通过轮询返回结果
        /// </summary>
        IN_PROCESS = 0x02,

        /// <summary>
        /// 某差错造成不能处理的命令，可重发 1 次
        /// </summary>
        CANNOT_PROCESS = 0x03,

        /// <summary>
        /// 命令收到，也正确，但不适合处理或不处理
        /// </summary>
        NO_PROCESS = 0x04,

        /// <summary>
        /// 收到交易数据，正确
        /// </summary>
        GOT_TRN_RIGHT = 0x05,

        /// <summary>
        /// 收到交易数据，T-MAC 错
        /// </summary>
        GOT_TRN_TMAC_ERR = 0x06

    }
}
