using System;
using QCRPG.Framework;

namespace QCRPG.TSL.ZigBee.Packets;

public class MlmeSetMacKeyTableInfo : PacketInfoBase
{
	public override string Name => "Mlme Set Mac Key Table";

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

	public MlmeSetMacKeyTableInfo(MlmeSetMacKeyTable packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		MlmeSetMacKeyTable mlmeSetMacKeyTable = (MlmeSetMacKeyTable)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("PIBAttribute", "The identifier of the PIB attribute to write", 8, FormatValue(mlmeSetMacKeyTable.UserFields.Pibattribute, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("PIBAttributeIndex", "", 8, FormatValue(mlmeSetMacKeyTable.UserFields.Pibattributeindex, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("PIBAttributeLength", "", 8, FormatValue(mlmeSetMacKeyTable.UserFields.Pibattributelength, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("IdMode", "", 8, FormatValue(mlmeSetMacKeyTable.UserFields.Idmode, 8), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Source", "", 64, FormatValue(mlmeSetMacKeyTable.UserFields.Source, 64), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Index", "", 8, FormatValue(mlmeSetMacKeyTable.UserFields.Index, 8), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("FrameUsage", "", 16, FormatValue(mlmeSetMacKeyTable.UserFields.Frameusage, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Key", "", mlmeSetMacKeyTable.UserFields.KeyList.Count * 8, FormatValue(mlmeSetMacKeyTable.UserFields.KeyList, mlmeSetMacKeyTable.UserFields.KeyList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

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