using Edge.Core.Parser.BinaryParser.Attributes;
using HengshanPaymentTerminal.Support;

namespace  HengshanPaymentTerminal.MessageEntity.Incoming
{
    /// <summary>
    /// Authorization request from terminal to system, 0x17.
    /// 授权请求，命令字0x17。
    /// </summary>
    public class AuthRequest : CardMessageBase
    {
        /// <summary>
        /// Constructor
        /// </summary>
        public AuthRequest() : base(Command.AuthRequest)
        {

        }

        /// <summary>
        /// Id of the terminal.
        /// 终端编号。
        /// </summary>
        [Format(4, EncodingType.BcdString, -90)]
        public string TerminalId { get; set; }

        /// <summary>
        /// Logical card number.
        /// 逻辑卡号。
        /// </summary>
        [Format(10, EncodingType.BcdString, -89)]
        public string Asn { get; set; }

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

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

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

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

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

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

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

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

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

        [Format(1, EncodingType.BIN, -79)]
        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()
                };
            }
        }
    }
}
