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

namespace  HengshanPaymentTerminal.MessageEntity.Incoming
{
    /// <summary>
    /// The request represents the fueling data from terminal after nozzle is returned, 0x1C.
    /// 标记为Nozzle_Down_Data
    /// Tag: Nozzle_Down_Data
    /// </summary>
    public class FuelingDataRequest : CardMessageBase
    {
        #region Constructor

        public FuelingDataRequest() : base(Command.FuelingData)
        {

        }

        #endregion

        #region Properties

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

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

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

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

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

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

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

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

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

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

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

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

        [Format(4, EncodingType.BIN, -78)]
        public int VolumeTotal { 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()
                };
            }
        }

        #endregion
    }
}
