using System;
using QCRPG.Framework;

namespace QCRPG.TSL.ZigBee.Packets;

public class VsNvmGet : PacketBase
{
	public class UserFieldsWrapper
	{
		private uint _Nvmtag;

		public uint Nvmtag
		{
			get
			{
				return _Nvmtag;
			}
			set
			{
				if (value > 65535)
				{
					throw new Exception("Maximum possible value for Nvmtag is 0xFFFF");
				}
				_Nvmtag = value;
			}
		}
	}

	private const uint _Packetcode = 136u;

	private Type[] expectedResponseTypes = new Type[1] { typeof(VsNvmGetConfirmation) };

	private PacketInfoBase info;

	public UserFieldsWrapper _UserFields = new UserFieldsWrapper();

	public override PacketType Type => PacketType.Command;

	public override Type[] ExpectedResponseTypes => expectedResponseTypes;

	public override PacketInfoBase Info
	{
		get
		{
			if (info == null)
			{
				info = new VsNvmGetInfo(this);
			}
			return info;
		}
	}

	public uint Packetcode => 136u;

	public UserFieldsWrapper UserFields => _UserFields;

	protected override bool FromBitBuilder(ref BitBuilder bitBuilder)
	{
		if (bitBuilder.RemoveBitsAsUintLittleEndian(8) != Packetcode)
		{
			return false;
		}
		UserFields.Nvmtag = bitBuilder.RemoveBitsAsUintLittleEndian(16);
		if (bitBuilder.GetNumberOfBits() > 7)
		{
			return false;
		}
		return true;
	}

	public override string ToBitString()
	{
		BitBuilder bitBuilder = new BitBuilder();
		bitBuilder.AddBitsAsUintLittleEndian(Packetcode, 8);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Nvmtag, 16);
		return bitBuilder.ToString();
	}
}
