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

namespace HengshanPaymentTerminal.MessageEntity.Outgoing
{
    /// <summary>
    /// 发送二维码至油机数据对象
    /// </summary>
    public class SendQrCode : CommonMessage
    {
        /// <summary>
        /// 油枪号
        /// </summary>
        public int NozzleNum {  get; set; }

        /// <summary>
        /// 小程序链接
        /// </summary>
        private string SmallProgram {  get; set; }

        public SendQrCode(int nozzle,string samllProgram,byte frame)
        {
            this.Handle = (byte)Command.SEND_QR_CODE;
            this.NozzleNum = nozzle;
            this.SmallProgram = samllProgram;
            this.FrameNum = frame;
        }

        public override byte[] ToCommonByteArray()
        {
            List<Byte> list = new List<Byte>();
            byte[] commandAndNozzle = { this.Handle, (byte)this.NozzleNum };
            string qrCode = this.SmallProgram + "/" + this.NozzleNum;
            byte[] qrCodeBytes = Encoding.ASCII.GetBytes(qrCode);
            list.AddRange(commandAndNozzle);
            list.Add((byte)qrCodeBytes.Length);
            list.AddRange(qrCodeBytes);
            byte[] sendBytes = content2data(list.ToArray());

            return sendBytes;
        }

        public override CommonMessage ToObject(byte[] datas)
        {
            return this;
        }
    }
}
