using System;
using QCRPG.Framework;

namespace QCRPG.TSL.ZigBee.Packets;

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

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

	public MlmeScanConfirmationEdInfo(MlmeScanConfirmationEd packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		MlmeScanConfirmationEd mlmeScanConfirmationEd = (MlmeScanConfirmationEd)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("PacketLength", "", 32, FormatValue(mlmeScanConfirmationEd.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(mlmeScanConfirmationEd.UserFields.Protocolid, 8), ProtocolIdInfo.ProtocolIdToString(ProtocolIdInfo.ValueToProtocolId(mlmeScanConfirmationEd.UserFields.Protocolid)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Event Code", CommandOpcodeInfo.CommandOpcodeToDescription(), 8, FormatValue(mlmeScanConfirmationEd.UserFields.EventCode, 8), CommandOpcodeInfo.CommandOpcodeToString(CommandOpcodeInfo.ValueToCommandOpcode(mlmeScanConfirmationEd.UserFields.EventCode)), "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Length", "Payload Length", 16, FormatValue(mlmeScanConfirmationEd.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(mlmeScanConfirmationEd.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(mlmeScanConfirmationEd.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(mlmeScanConfirmationEd.UserFields.Scantype, 8), MlmeScanTypeInfo.MlmeScanTypeToString(MlmeScanTypeInfo.ValueToMlmeScanType(mlmeScanConfirmationEd.UserFields.Scantype)), "0x00", "0x00", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("ChPage", "The channel page on which to perform the scan", 8, FormatValue(mlmeScanConfirmationEd.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(mlmeScanConfirmationEd.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(mlmeScanConfirmationEd.UserFields.Resultlistsize, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < mlmeScanConfirmationEd.UserFields.PayloadList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Ch[" + i + "]", "", 8, FormatValue(mlmeScanConfirmationEd.UserFields.PayloadList[i].Ch, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		MlmeScanConfirmationEd mlmeScanConfirmationEd = (MlmeScanConfirmationEd)packet;
		int num = -1;
		if (index == ++num)
		{
			mlmeScanConfirmationEd.UserFields.Packetlength = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			mlmeScanConfirmationEd.UserFields.Protocolid = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field EventCode");
		}
		if (index == ++num)
		{
			mlmeScanConfirmationEd.UserFields.Length = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			mlmeScanConfirmationEd.UserFields.Status = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			mlmeScanConfirmationEd.UserFields.Scantype = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			mlmeScanConfirmationEd.UserFields.Chpage = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			mlmeScanConfirmationEd.UserFields.Unscannedchannels = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			mlmeScanConfirmationEd.UserFields.Resultlistsize = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < mlmeScanConfirmationEd.UserFields.PayloadList.Count; i++)
		{
			if (index == ++num)
			{
				mlmeScanConfirmationEd.UserFields.PayloadList[i].Ch = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
