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(IDMReadBuffer buffer)
        {
            SerialNumber = buffer.TakeUInt32();
            IMEI = buffer.TakeString(16);
            ICCID = buffer.TakeString(21);
            ProductID = buffer.TakeByte();
            HardwareRevision = buffer.TakeByte();
            FirmwareMajor = buffer.TakeByte();
            FirmwareMinor = buffer.TakeByte();
            Flags = buffer.TakeUInt32();
        }

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

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