using System.Text;

namespace InABox.DigitalMatter
{
    public class DMHelloRequest : DMMessage
    {
        public override byte Type => 0x00;

        public uint SerialNumber { get; set; }

        public string IMEI { get; set; }

        public string ICCID { get; set; }

        public byte ProductID { get; set; }

        public byte HardwareRevision { get; set; }

        public byte FirmwareMajor { get; set; }

        public byte FirmwareMinor { get; set; }

        public uint Flags { get; set; }

        protected override void DoDecode()
        {
            SerialNumber = TakeUInt32();
            IMEI = TakeString(16);
            ICCID = TakeString(21);
            ProductID = TakeByte();
            HardwareRevision = TakeByte();
            FirmwareMajor = TakeByte();
            FirmwareMinor = TakeByte();
            Flags = TakeUInt32();
        }

        protected override void DoEncode()
        {
            AddUInt32(SerialNumber);
            AddString(IMEI, 16);
            AddString(ICCID, 21);
            AddByte(ProductID);
            AddByte(HardwareRevision);
            AddByte(FirmwareMajor);
            AddByte(FirmwareMinor);
            AddUInt32(Flags);
        }

        public override byte[] Dump()
        {
            return Encoding.UTF8.GetBytes($"(HelloRequest) SerialNumber: {SerialNumber}");
        }
    }
}