using System;
using QCRPG.Framework;

namespace QCRPG.TSL.ZigBee.Packets;

public class VsPokeRequestInfo : PacketInfoBase
{
	public override string Name => "Vs Poke Request";

	public override string DisplayGroup => "Vendor Specific Packets";

	public VsPokeRequestInfo(VsPokeRequest packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		VsPokeRequest vsPokeRequest = (VsPokeRequest)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("ElementSize", "", 8, FormatValue(vsPokeRequest.UserFields.Elementsize, 8), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("NumElements", "", 8, FormatValue(vsPokeRequest.UserFields.Numelements, 8), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Address", "", 32, FormatValue(vsPokeRequest.UserFields.Address, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("DataLength", "", 8, FormatValue(vsPokeRequest.UserFields.Datalength, 8), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: true, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Data", "", vsPokeRequest.UserFields.DataList.Count * 8, FormatValue(vsPokeRequest.UserFields.DataList, vsPokeRequest.UserFields.DataList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		VsPokeRequest vsPokeRequest = (VsPokeRequest)packet;
		int num = -1;
		if (index == ++num)
		{
			vsPokeRequest.UserFields.Elementsize = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			vsPokeRequest.UserFields.Numelements = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			vsPokeRequest.UserFields.Address = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			vsPokeRequest.UserFields.Datalength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, vsPokeRequest.UserFields.DataList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				vsPokeRequest.UserFields.DataList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
