using System;
using QCRPG.Framework;

namespace QCRPG.TSL.ZigBee.Packets;

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

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

	public MlmeScanInfo(MlmeScan packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		MlmeScan mlmeScan = (MlmeScan)packet;
		fieldInfoList.Clear();
		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(mlmeScan.UserFields.Scantype, 8), MlmeScanTypeInfo.MlmeScanTypeToString(MlmeScanTypeInfo.ValueToMlmeScanType(mlmeScan.UserFields.Scantype)), "", "0x03", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("ScanChannels", "The 27 bits (b0, b1,... b26) indicate which channels are to be scanned (1 = scan, 0 = do not scan) for each of the 27 channels supported by the ChannelPage parameter", 32, FormatValue(mlmeScan.UserFields.Scanchannels, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("ScanDuration", "A value used to calculate the length of time to spend scanning each channel for ED, active, and passive scans. This parameter is ignored for orphan scans. The time spent scanning each channel is [aBaseSuperframeDuration * (2n + 1)] symbols, where n is the value of the ScanDuration parameter", 32, FormatValue(mlmeScan.UserFields.Scanduration, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("ChannelPage", "The channel page on which to perform the scan", 8, FormatValue(mlmeScan.UserFields.Channelpage, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("SecurityLevel", "The security level to be used\r\n\r\n" + SecurityLevelOptionsInfo.SecurityLevelOptionsToDescription(), 8, FormatValue(mlmeScan.UserFields.Securitylevel, 8), SecurityLevelOptionsInfo.SecurityLevelOptionsToString(SecurityLevelOptionsInfo.ValueToSecurityLevelOptions(mlmeScan.UserFields.Securitylevel)), "0", "7", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("KeyIdMode", "The mode used to identify the key to be used. This parameter is ignored if the SecurityLevel parameter is set to 0x00", 8, FormatValue(mlmeScan.UserFields.Keyidmode, 8), "", "0", "3", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("KeySource", "The originator of the key to be used. This parameter is ignored if the KeyIdMode parameter is ignored or set to 0x00", 64, FormatValue(mlmeScan.UserFields.Keysource, 64), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("KeyIndex", "The index of the key to be used. This parameter is ignored if the KeyIdMode parameter is ignored or set to 0x00", 8, FormatValue(mlmeScan.UserFields.Keyindex, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		MlmeScan mlmeScan = (MlmeScan)packet;
		int num = -1;
		if (index == ++num)
		{
			mlmeScan.UserFields.Scantype = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeScan.UserFields.Scanchannels = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeScan.UserFields.Scanduration = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeScan.UserFields.Channelpage = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeScan.UserFields.Securitylevel = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeScan.UserFields.Keyidmode = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeScan.UserFields.Keysource = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			mlmeScan.UserFields.Keyindex = Convert.ToUInt32(value, 16);
		}
	}
}
