using Edge.Core.Parser.BinaryParser.Attributes;
using HengshanPaymentTerminal.Support;
using System;
using System.Collections.Generic;
using System.Text;

namespace  HengshanPaymentTerminal.MessageEntity.Incoming
{
    public class CancelAuthRequest : CardMessageBase
    {
        public CancelAuthRequest() : base(Command.CancelAuthRequest)
        {

        }

        [Format(4, EncodingType.BcdString, -90)]
        public string TerminalId { get; set; }

        [Format(10, EncodingType.BcdString, -89)]
        public string Asn { get; set; }

        [Format(7, EncodingType.BcdString, -88)]
        public string TransactionTime { get; set; }

        [Format(4, EncodingType.BIN, -87)]
        public int PosTtc { get; set; }

        [Format(2, EncodingType.BIN, -86)]
        public ushort SeqNo { get; set; }

        /// <summary>
        /// AccountType
        /// 0x50表示实际金额中得定量数目单位为0.01元，0x51表示实际金额中得定量数目单位为0.01升
        /// </summary>
        [Format(1, EncodingType.BIN, -85)]
        public byte PresetType { get; set; }

        [Format(2, EncodingType.HexString, -84)]
        public string FPCode { get; set; }

        [Format(3, EncodingType.HexString, -83)]
        public string CardInfo { get; set; }

        [Format(1, EncodingType.BIN, -82)]
        public byte PaymentType { get; set; }

        public CardInfo CurrentCardInfo
        {
            get
            {
                return new CardInfo
                {
                    CardType = CardInfo.Substring(0, 2).ToByte(),
                    CardCtc = CardInfo.Substring(2, 4).ToUInt16()
                };
            }
        }

        public FuelingPointCode FuelingPoint
        {
            get
            {
                return new FuelingPointCode
                {
                    NozzleNo = FPCode.Substring(0, 2).ToByte(),
                    PumpNo = FPCode.Substring(2, 2).ToByte()
                };
            }
        }
    }
}
