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

namespace  HengshanPaymentTerminal.MessageEntity.Incoming
{
    /// <summary>
    /// IC terminal on pump requests card validation on system
    /// 油机卡终端向后台发起验卡请求
    /// Sample: FA010161001C1500000001000000000000100105536DCA9D06010103001800025EC8FF3258
    /// Analysis: FA 01 01 61 001C 15 00000001 00000000000010010553 6DCA9D06 0101 030018 00025EC8 FF 3258
    /// </summary>
    public class ValidateCardRequest : CardMessageBase
    {
        #region Constructor

        public ValidateCardRequest() : base(Command.ValidateCardRequest)
        {

        }

        #endregion

        #region Properties

        /// <summary>
        /// The ID of the IC card terminal.
        /// 终端编号，类型：压缩BCD，4字节
        /// </summary>
        [Format(4, EncodingType.BcdString, -90)]
        public string TerminalID { get; set; }

        /// <summary>
        /// Logical card number.
        /// 逻辑卡号，类型：压缩BCD，10字节
        /// </summary>
        [Format(10, EncodingType.BcdString, -89)]
        public string Asn { get; set; }

        /// <summary>
        /// The physical card number.
        /// 物理卡号，HEX，4字节
        /// </summary>
        [Format(4, EncodingType.ReverseHexString, -88)]
        public string PhysicalCardNo { get; set; }

        /// <summary>
        /// Fueling poing code, 1 byte nozzle number, 1 byte pump number.
        /// 加油点编号，HEX，2字节，1字节油枪号，1字节泵编号
        /// </summary>
        [Format(2, EncodingType.HexString, -87)]
        public string FPCode { get; set; }

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

        /// <summary>
        /// Card balance.
        /// 卡钱包余额，HEX，4字节
        /// </summary>
        [Format(4, EncodingType.BIN, -85)]
        public int Balance { get; set; }

        //THIS FIELD WAS SPECIFIED BUT NOT USED.
        /// <summary>
        /// Time stamp of the transaction.
        /// 交易时间，压缩BCD，7字节
        /// </summary>
        public DateTime DispenserTime { get; set; }

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

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

        #endregion
    }
}
