using Edge.Core.IndustryStandardInterface.Pump.Fdc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HengshanPaymentTerminal.MessageEntity.Incoming
{
    /// <summary>
    /// 心跳包数据对象
    /// </summary>
    public class HeartBeatMessage : CommonMessage
    {
        /// <summary>
        /// 油枪数
        /// </summary>
        public int GunCount { get; set; }

        /// <summary>
        /// 各油枪状态
        /// </summary>
        public List<HeartBeatNozzleState> NozzleStatus { get; set; }
        
        public override CommonMessage ToObject(byte[] datas)
        {
            this.getBaseData(datas);
            this.GunCount = datas[7];
            List<HeartBeatNozzleState> nozzleStates = new List<HeartBeatNozzleState>();
            for (int index = 8;index < datas.Length - 2;index += 2)
            {
                HeartBeatNozzleState nozzle = new HeartBeatNozzleState()
                {
                    NozzleNum = datas[index],
                    STATU = datas[index + 1]
                };
                nozzleStates.Add(nozzle);
            }
            this.NozzleStatus = nozzleStates;
            return this;
        }

        public override byte[] ToCommonByteArray()
        {
            byte[] content = new byte[] { 0x55, this.Handle, 0x00, ((byte)RESULT.OVER) };
            return content2data(content);
        }
    }

    public class HeartBeatNozzleState
    {
        /// <summary>
        /// 油枪号
        /// </summary>
        public int NozzleNum { get; set; }

        /// <summary>
        /// 油枪状态 01：不可用  02：关闭  03：空闲  04：呼叫  05：授权  06：开始加油  07：挂起开始加油  08：加油中  09：挂起加油
        /// </summary>
        public int STATU { get; set; }
    }
}
