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

namespace HengshanPaymentTerminal.MessageEntity.Outgoing
{
    public class SendRefund:CommonMessage
    {

        /// <summary>
        /// 油枪号
        /// </summary>
        public int NozzleNum { get; set; }

        /// <summary>
        /// 流水号
        /// </summary>
        public int TTC { get; set; }

        /// <summary>
        /// 支付方式、地点。无效数据，占位。用0x21表示二维码订单
        /// </summary>
        public byte Pay_X {  get; set; }

        /// <summary>
        /// 加油金额
        /// </summary>
        public decimal Amount { get; set; }

        /// <summary>
        /// 实付金额
        /// </summary>
        public decimal AmountPayable { get; set; }

        /// <summary>
        /// 退款金额
        /// </summary>
        public decimal Refund {  get; set; }
        public SendRefund(int nozzle, string ttc,decimal amount,decimal amountPayable,decimal refund, byte frame)
        {
            this.Handle = (byte)Command.SEND_REFUND;
            this.NozzleNum = nozzle;

            int.TryParse(ttc,out int ttcNum);
            this.TTC = ttcNum;
            this.Pay_X = 0x21;
            this.Amount = amount;
            this.AmountPayable = amountPayable;
            this.Refund = refund;
            this.FrameNum = frame;
        }

        public override byte[] ToCommonByteArray()
        {
            List<Byte> list = new List<Byte>();
            byte[] commandAndNozzle = { this.Handle, (byte)this.NozzleNum };
            byte[] ttcBytes = NumberToByteArrayWithPadding(this.TTC, 4);

            //加油金额
            //int amount = (int)(this.Amount * 100);
            byte[] amountBytes = FormatDecimal(this.Amount);

            //实付金额
            //int amountPayable = (int)(this.AmountPayable * 100);
            byte[] amountPayableBytes = FormatDecimal(this.AmountPayable);

            //退款金额
            //int refund = (int)(this.Refund * 100);
            byte[] refundBytes = FormatDecimal(this.Refund);


            list.AddRange(commandAndNozzle);
            list.AddRange(ttcBytes);
            list.Add(this.Pay_X);
            list.AddRange(amountBytes);
            list.AddRange(amountPayableBytes);
            list.AddRange(refundBytes);

            byte[] sendBytes = content2data(list.ToArray());

            return sendBytes;
        }

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