using System;
using QCRPG.Framework;

namespace QCRPG.TSL.ZigBee.Packets;

public class MlmeGetConfirmationMacKeyTableInfo : PacketInfoBase
{
	public override string Name => "Mlme Get Confirmation Mac Key Table";

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

	public MlmeGetConfirmationMacKeyTableInfo(MlmeGetConfirmationMacKeyTable packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		MlmeGetConfirmationMacKeyTable mlmeGetConfirmationMacKeyTable = (MlmeGetConfirmationMacKeyTable)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("PacketLength", "", 32, FormatValue(mlmeGetConfirmationMacKeyTable.UserFields.Packetlength, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("ProtocolID", "ProtocolID\r\n\r\n" + ProtocolIdInfo.ProtocolIdToDescription(), 8, FormatValue(mlmeGetConfirmationMacKeyTable.UserFields.Protocolid, 8), ProtocolIdInfo.ProtocolIdToString(ProtocolIdInfo.ValueToProtocolId(mlmeGetConfirmationMacKeyTable.UserFields.Protocolid)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Event Code", CommandOpcodeInfo.CommandOpcodeToDescription(), 8, FormatValue(mlmeGetConfirmationMacKeyTable.UserFields.EventCode, 8), CommandOpcodeInfo.CommandOpcodeToString(CommandOpcodeInfo.ValueToCommandOpcode(mlmeGetConfirmationMacKeyTable.UserFields.EventCode)), "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Length", "Payload Length", 16, FormatValue(mlmeGetConfirmationMacKeyTable.UserFields.Length, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", "Status\r\n\r\n" + ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(mlmeGetConfirmationMacKeyTable.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(mlmeGetConfirmationMacKeyTable.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("PIBAttribute", "PIBAttribute\r\n\r\n" + PibattributekeytableInfo.PibattributekeytableToDescription(), 8, FormatValue(mlmeGetConfirmationMacKeyTable.UserFields.Pibattribute, 8), PibattributekeytableInfo.PibattributekeytableToString(PibattributekeytableInfo.ValueToPibattributekeytable(mlmeGetConfirmationMacKeyTable.UserFields.Pibattribute)), "71", "71", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("PIBAttributeIndex", "", 8, FormatValue(mlmeGetConfirmationMacKeyTable.UserFields.Pibattributeindex, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("PIBAttributeLength", "The index within the table of the specified PIB attribute to write. This parameter is valid only for MAC PIB attributes that are tables; it is ignored when accessing PHY PIB attributes", 8, FormatValue(mlmeGetConfirmationMacKeyTable.UserFields.Pibattributelength, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("IdMode", "", 8, FormatValue(mlmeGetConfirmationMacKeyTable.UserFields.Idmode, 8), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Source", "", 64, FormatValue(mlmeGetConfirmationMacKeyTable.UserFields.Source, 64), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Index", "", 8, FormatValue(mlmeGetConfirmationMacKeyTable.UserFields.Index, 8), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("FrameUsage", "", 16, FormatValue(mlmeGetConfirmationMacKeyTable.UserFields.Frameusage, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Key", "", mlmeGetConfirmationMacKeyTable.UserFields.KeyList.Count * 8, FormatValue(mlmeGetConfirmationMacKeyTable.UserFields.KeyList, mlmeGetConfirmationMacKeyTable.UserFields.KeyList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

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