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

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

        }

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

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

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

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

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

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

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

        [Format(3, EncodingType.BIN, -83)]
        public int FillingAmount { get; set; }

        [Format(3, EncodingType.BIN, -82)]
        public int PaymentAmount { get; set; }

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

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

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

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

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

        [Format(2, EncodingType.BCD, -75)]
        public int ProductCode { get; set; }

        [Format(3, EncodingType.BIN, -74)]
        public int Volume { get; set; }

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

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

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

        [Format(4, EncodingType.HexString, -70)]
        public string PsamTac { get; set; }

        [Format(6, EncodingType.BcdString, -69)]
        public string PsamTid { get; set; }

        [Format(4, EncodingType.HexString, -68)]
        public string PsamTtc { get; set; }

        [Format(4, EncodingType.HexString, -67)]
        public string Tac { get; set; }

        [Format(4, EncodingType.HexString, -66)]
        public string Gmac { get; set; }

        [Format(4, EncodingType.HexString, -65)]
        public string Tmac { get; set; }

        [Format(3, EncodingType.BcdString, -64)]
        public string LineCode { get; set; }

        [Format(3, EncodingType.BcdString, -63)]
        public string CarCode { get; set; }

        [Format(16, EncodingType.HexString, -62)]
        public string VehicleNo { get; set; }

        [Format(4, EncodingType.BcdString, -61)]
        public string LoyaltyCardNo { 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()
                };
            }
        }
    }
}
