using System;
using QCRPG.Framework;

namespace QCRPG.TSL.ZigBee.Packets;

public class MlmePollInfo : PacketInfoBase
{
	public override string Name => "Mlme Poll";

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

	public MlmePollInfo(MlmePoll packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		MlmePoll mlmePoll = (MlmePoll)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("CoordAddrMode", "The addressing mode of the coordinator to which the poll is intended. This parameter can take one of the following values: 2 = 16-bit short address, 3 = 64-bit extended address.\r\n\r\n" + DutaddressmodeInfo.DutaddressmodeToDescription(), 8, FormatValue(mlmePoll.UserFields.Coordaddrmode, 8), DutaddressmodeInfo.DutaddressmodeToString(DutaddressmodeInfo.ValueToDutaddressmode(mlmePoll.UserFields.Coordaddrmode)), "2", "3", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("CoordPANId", "The PAN identifier of the coordinator to which the poll is intended.", 16, FormatValue(mlmePoll.UserFields.Coordpanid, 16), "", "0000", "0xFFFE", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("CoordAddress", "The address of the coordinator to which the poll is intended.", 64, FormatValue(mlmePoll.UserFields.Coordaddress, 64), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("SecurityLevel", "The security level to be used\r\n\r\n" + SecurityLevelOptionsInfo.SecurityLevelOptionsToDescription(), 8, FormatValue(mlmePoll.UserFields.Securitylevel, 8), SecurityLevelOptionsInfo.SecurityLevelOptionsToString(SecurityLevelOptionsInfo.ValueToSecurityLevelOptions(mlmePoll.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(mlmePoll.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(mlmePoll.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(mlmePoll.UserFields.Keyindex, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		MlmePoll mlmePoll = (MlmePoll)packet;
		int num = -1;
		if (index == ++num)
		{
			mlmePoll.UserFields.Coordaddrmode = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmePoll.UserFields.Coordpanid = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmePoll.UserFields.Coordaddress = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			mlmePoll.UserFields.Securitylevel = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmePoll.UserFields.Keyidmode = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmePoll.UserFields.Keysource = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			mlmePoll.UserFields.Keyindex = Convert.ToUInt32(value, 16);
		}
	}
}
