using System;
using QCRPG.Framework;

namespace QCRPG.TSL.ZigBee.Packets;

public class MlmeScanConfirmationInfo : PacketInfoBase
{
	public override string Name => "Mlme Scan Confirmation";

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

	public MlmeScanConfirmationInfo(MlmeScanConfirmation packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		MlmeScanConfirmation mlmeScanConfirmation = (MlmeScanConfirmation)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("PacketLength", "", 32, FormatValue(mlmeScanConfirmation.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(mlmeScanConfirmation.UserFields.Protocolid, 8), ProtocolIdInfo.ProtocolIdToString(ProtocolIdInfo.ValueToProtocolId(mlmeScanConfirmation.UserFields.Protocolid)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Event Code", CommandOpcodeInfo.CommandOpcodeToDescription(), 8, FormatValue(mlmeScanConfirmation.UserFields.EventCode, 8), CommandOpcodeInfo.CommandOpcodeToString(CommandOpcodeInfo.ValueToCommandOpcode(mlmeScanConfirmation.UserFields.EventCode)), "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Length", "Payload Length", 16, FormatValue(mlmeScanConfirmation.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(mlmeScanConfirmation.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(mlmeScanConfirmation.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("ScanType", "0x00 = ED scan (optional for RFD).0x01 = active scan (optional for RFD).0x02 = passive scan.0x03 = orphan scan.\r\n\r\n" + MlmeScanTypeInfo.MlmeScanTypeToDescription(), 8, FormatValue(mlmeScanConfirmation.UserFields.Scantype, 8), MlmeScanTypeInfo.MlmeScanTypeToString(MlmeScanTypeInfo.ValueToMlmeScanType(mlmeScanConfirmation.UserFields.Scantype)), "0x01", "0x03", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("ChPage", "The channel page on which to perform the scan", 8, FormatValue(mlmeScanConfirmation.UserFields.Chpage, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("UnscannedChannels", "Indicates which channels given in the request were not scanned (1 = not scanned, 0 = scanned or not requested). This parameter is not valid for ED scans.", 32, FormatValue(mlmeScanConfirmation.UserFields.Unscannedchannels, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("ResultListSize", "The number of elements returned in the appropriate result lists. This value is zero for the result of an orphan scan.", 8, FormatValue(mlmeScanConfirmation.UserFields.Resultlistsize, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < mlmeScanConfirmation.UserFields.PandescriptorList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("CoordAddrMode[" + i + "]", "The coordinator addressing mode for this primitive and subsequent MPDU\r\n\r\n" + DutaddressmodeInfo.DutaddressmodeToDescription(), 8, FormatValue(mlmeScanConfirmation.UserFields.PandescriptorList[i].Coordaddrmode, 8), DutaddressmodeInfo.DutaddressmodeToString(DutaddressmodeInfo.ValueToDutaddressmode(mlmeScanConfirmation.UserFields.PandescriptorList[i].Coordaddrmode)), "2", "3", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("CoordPANId[" + i + "]", "The identifier of the PAN with which to associate", 16, FormatValue(mlmeScanConfirmation.UserFields.PandescriptorList[i].Coordpanid, 16), "", "0000", "0xFFFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("CoordAddress[" + i + "]", "The address of the coordinator with which to associate", 64, FormatValue(mlmeScanConfirmation.UserFields.PandescriptorList[i].Coordaddress, 64), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("LogicalChannel[" + i + "]", "The logical channel on which to attempt association", 8, FormatValue(mlmeScanConfirmation.UserFields.PandescriptorList[i].Logicalchannel, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("ChannelPage[" + i + "]", "The channel page on which to attempt association", 8, FormatValue(mlmeScanConfirmation.UserFields.PandescriptorList[i].Channelpage, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("SuperframeSpec[" + i + "]", "", 16, FormatValue(mlmeScanConfirmation.UserFields.PandescriptorList[i].Superframespec, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("GTSPermit[" + i + "]", "", 8, FormatValue(mlmeScanConfirmation.UserFields.PandescriptorList[i].Gtspermit, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("LinkQuality[" + i + "]", "", 16, FormatValue(mlmeScanConfirmation.UserFields.PandescriptorList[i].Linkquality, 16), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Timestamp[" + i + "]", "", 32, FormatValue(mlmeScanConfirmation.UserFields.PandescriptorList[i].Timestamp, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("SecurityFailure[" + i + "]", "", 8, FormatValue(mlmeScanConfirmation.UserFields.PandescriptorList[i].Securityfailure, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("SecurityLevel[" + i + "]", "The security level to be used\r\n\r\n" + SecurityLevelOptionsInfo.SecurityLevelOptionsToDescription(), 8, FormatValue(mlmeScanConfirmation.UserFields.PandescriptorList[i].Securitylevel, 8), SecurityLevelOptionsInfo.SecurityLevelOptionsToString(SecurityLevelOptionsInfo.ValueToSecurityLevelOptions(mlmeScanConfirmation.UserFields.PandescriptorList[i].Securitylevel)), "0", "7", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("KeyIdMode[" + i + "]", "The mode used to identify the key to be used. This parameter is ignored if the SecurityLevel parameter is set to 0x00", 8, FormatValue(mlmeScanConfirmation.UserFields.PandescriptorList[i].Keyidmode, 8), "", "0", "3", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("KeySource[" + i + "]", "The originator of the key to be used. This parameter is ignored if the KeyIdMode parameter is ignored or set to 0x00", 64, FormatValue(mlmeScanConfirmation.UserFields.PandescriptorList[i].Keysource, 64), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("KeyIndex[" + i + "]", "The index of the key to be used. This parameter is ignored if the KeyIdMode parameter is ignored or set to 0x00", 8, FormatValue(mlmeScanConfirmation.UserFields.PandescriptorList[i].Keyindex, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		MlmeScanConfirmation mlmeScanConfirmation = (MlmeScanConfirmation)packet;
		int num = -1;
		if (index == ++num)
		{
			mlmeScanConfirmation.UserFields.Packetlength = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			mlmeScanConfirmation.UserFields.Protocolid = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field EventCode");
		}
		if (index == ++num)
		{
			mlmeScanConfirmation.UserFields.Length = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			mlmeScanConfirmation.UserFields.Status = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			mlmeScanConfirmation.UserFields.Scantype = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			mlmeScanConfirmation.UserFields.Chpage = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			mlmeScanConfirmation.UserFields.Unscannedchannels = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			mlmeScanConfirmation.UserFields.Resultlistsize = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < mlmeScanConfirmation.UserFields.PandescriptorList.Count; i++)
		{
			if (index == ++num)
			{
				mlmeScanConfirmation.UserFields.PandescriptorList[i].Coordaddrmode = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				mlmeScanConfirmation.UserFields.PandescriptorList[i].Coordpanid = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				mlmeScanConfirmation.UserFields.PandescriptorList[i].Coordaddress = Convert.ToUInt64(value, 16);
				break;
			}
			if (index == ++num)
			{
				mlmeScanConfirmation.UserFields.PandescriptorList[i].Logicalchannel = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				mlmeScanConfirmation.UserFields.PandescriptorList[i].Channelpage = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				mlmeScanConfirmation.UserFields.PandescriptorList[i].Superframespec = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				mlmeScanConfirmation.UserFields.PandescriptorList[i].Gtspermit = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				mlmeScanConfirmation.UserFields.PandescriptorList[i].Linkquality = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				mlmeScanConfirmation.UserFields.PandescriptorList[i].Timestamp = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				mlmeScanConfirmation.UserFields.PandescriptorList[i].Securityfailure = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				mlmeScanConfirmation.UserFields.PandescriptorList[i].Securitylevel = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				mlmeScanConfirmation.UserFields.PandescriptorList[i].Keyidmode = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				mlmeScanConfirmation.UserFields.PandescriptorList[i].Keysource = Convert.ToUInt64(value, 16);
				break;
			}
			if (index == ++num)
			{
				mlmeScanConfirmation.UserFields.PandescriptorList[i].Keyindex = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
