using System;
using QCRPG.Framework;

namespace QCRPG.TSL.ZigBee.Packets;

public class MlmeSetInfo : PacketInfoBase
{
	public override string Name => "Mlme Set";

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

	public MlmeSetInfo(MlmeSet packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

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

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		MlmeSet mlmeSet = (MlmeSet)packet;
		int num = -1;
		if (index == ++num)
		{
			mlmeSet.UserFields.Pibattribute = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeSet.UserFields.Pibattributeindex = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeSet.UserFields.Pibattributelength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, mlmeSet.UserFields.PibattributevalueList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				mlmeSet.UserFields.PibattributevalueList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
