using ProjectManagementSystem.Device.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProjectManagementSystem.Device.CommandCallback
{
    public class InfoRoller : BaseInfo, IDeviceCommandCallback
    {
        public int DeviceId { get; set; }
        public bool FullTray { get; set; }
        public bool FullEmpty { get; set; }
        public bool CallButton { get; set; }

        public bool Rotating1 { get; set; }
        public bool Rotating2 { get; set; }
        public bool Rotating3 { get; set; }
        public bool Rotating4 { get; set; }

        public bool Brake1 { get; set; }
        public bool Brake2 { get; set; }
        public bool Brake3 { get; set; }
        public bool Brake4 { get; set; }

        public byte OperationProgress { get; set; }
        public void Deserialize(byte[] data)
        {
            DeviceId = data[2];
            FullTray = data[6] == 0x01;
            CallButton = (data[22] & 0x02) > 0;

            Rotating1 = (data[32] & 0x01) > 0;
            Rotating2 = (data[32] & 0x02) > 0;
            Rotating3 = (data[32] & 0x04) > 0;
            Rotating4 = (data[32] & 0x08) > 0;

            Brake1 = (data[32] & 0x10) > 0;
            Brake2 = (data[32] & 0x20) > 0;
            Brake3 = (data[32] & 0x40) > 0;
            Brake4 = (data[32] & 0x80) > 0;

            FullEmpty =
                (data[18] & 0x10) == 0
                && (data[18] & 0x20) == 0
                && (data[18] & 0x40) == 0
                && (data[18] & 0x80) == 0
                && (data[19] & 0x01) == 0
                && (data[19] & 0x02) == 0
                && (data[19] & 0x04) == 0
                && (data[19] & 0x08) == 0;

            OperationProgress = data[17];

            LastUpdateTime = DateTime.Now;
        }
    }
}
