using System;
using QCRPG.Framework;

namespace QCRPG.TSL.ZigBee.Packets;

public class MlmeSetBeaconPayloadInfo : PacketInfoBase
{
	public override string Name => "Mlme Set Beacon Payload";

	public override string DisplayGroup => "MLME Request Packets";

	public MlmeSetBeaconPayloadInfo(MlmeSetBeaconPayload packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		MlmeSetBeaconPayload mlmeSetBeaconPayload = (MlmeSetBeaconPayload)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("PIBAttribute", "The identifier of the PIB attribute to write", 8, FormatValue(mlmeSetBeaconPayload.UserFields.Pibattribute, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("PIBAttributeIndex", "", 8, FormatValue(mlmeSetBeaconPayload.UserFields.Pibattributeindex, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("PIBAttributeLength", "", 8, FormatValue(mlmeSetBeaconPayload.UserFields.Pibattributelength, 8), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("PIBAttributeValue", "", mlmeSetBeaconPayload.UserFields.PibattributevalueList.Count * 8, FormatValue(mlmeSetBeaconPayload.UserFields.PibattributevalueList, mlmeSetBeaconPayload.UserFields.PibattributevalueList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		MlmeSetBeaconPayload mlmeSetBeaconPayload = (MlmeSetBeaconPayload)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field Pibattribute");
		}
		if (index == ++num)
		{
			mlmeSetBeaconPayload.UserFields.Pibattributeindex = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeSetBeaconPayload.UserFields.Pibattributelength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, mlmeSetBeaconPayload.UserFields.PibattributevalueList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				mlmeSetBeaconPayload.UserFields.PibattributevalueList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
