using System;
using QCRPG.Framework;

namespace QCRPG.TSL.ZigBee.Packets;

public class MlmeAssociateInfo : PacketInfoBase
{
	public override string Name => "Mlme Associate";

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

	public MlmeAssociateInfo(MlmeAssociate packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		MlmeAssociate mlmeAssociate = (MlmeAssociate)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("LogicalChannel", "The logical channel on which to attempt association", 8, FormatValue(mlmeAssociate.UserFields.Logicalchannel, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("ChannelPage", "The channel page on which to attempt association", 8, FormatValue(mlmeAssociate.UserFields.Channelpage, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("CoordAddrMode", "The coordinator addressing mode for this primitive and subsequent MPDU\r\n\r\n" + DutaddressmodeInfo.DutaddressmodeToDescription(), 8, FormatValue(mlmeAssociate.UserFields.Coordaddrmode, 8), DutaddressmodeInfo.DutaddressmodeToString(DutaddressmodeInfo.ValueToDutaddressmode(mlmeAssociate.UserFields.Coordaddrmode)), "2", "3", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("CoordPANId", "The identifier of the PAN with which to associate", 16, FormatValue(mlmeAssociate.UserFields.Coordpanid, 16), "", "0000", "0xFFFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("CoordAddress", "The address of the coordinator with which to associate", 64, FormatValue(mlmeAssociate.UserFields.Coordaddress, 64), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("CapabilityInformation", "Specifies the operational capabilities of the associating device\r\n\r\n" + MlmeAssociate.UserFieldsWrapper.CapabilityinformationInfo.CapabilityinformationToDescription(), 8, FormatValue(mlmeAssociate.UserFields.Capabilityinformation, 8), MlmeAssociate.UserFieldsWrapper.CapabilityinformationInfo.CapabilityinformationToString(MlmeAssociate.UserFieldsWrapper.CapabilityinformationInfo.ValueToCapabilityinformation(mlmeAssociate.UserFields.Capabilityinformation)), "", "", 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(mlmeAssociate.UserFields.Securitylevel, 8), SecurityLevelOptionsInfo.SecurityLevelOptionsToString(SecurityLevelOptionsInfo.ValueToSecurityLevelOptions(mlmeAssociate.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(mlmeAssociate.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(mlmeAssociate.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(mlmeAssociate.UserFields.Keyindex, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

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