using System;
using QCRPG.Framework;

namespace QCRPG.TSL.ZigBee.Packets;

public class MlmeOrphanResponseInfo : PacketInfoBase
{
	public override string Name => "Mlme Orphan Response";

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

	public MlmeOrphanResponseInfo(MlmeOrphanResponse packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		MlmeOrphanResponse mlmeOrphanResponse = (MlmeOrphanResponse)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("OrphanAddress", "The address of the orphaned device", 64, FormatValue(mlmeOrphanResponse.UserFields.Orphanaddress, 64), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("ShortAddress", "The 16-bit short address allocated to the orphaned device if it is associated with this coordinator. The special short address 0xfffe indicates that no short address was allocated, and the device will use its 64-bit extended address in all communications. If the device was not associated with this coordinator, this field will contain the value 0xffff and be ignored on receipt", 16, FormatValue(mlmeOrphanResponse.UserFields.Shortaddress, 16), "", "0000", "0xFFFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("AssociatedMember", "TRUE if the orphaned device is associated with this coordinator or FALSE otherwise", 8, FormatValue(mlmeOrphanResponse.UserFields.Associatedmember, 8), "", "00", "0x01", 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(mlmeOrphanResponse.UserFields.Securitylevel, 8), SecurityLevelOptionsInfo.SecurityLevelOptionsToString(SecurityLevelOptionsInfo.ValueToSecurityLevelOptions(mlmeOrphanResponse.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(mlmeOrphanResponse.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(mlmeOrphanResponse.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(mlmeOrphanResponse.UserFields.Keyindex, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		MlmeOrphanResponse mlmeOrphanResponse = (MlmeOrphanResponse)packet;
		int num = -1;
		if (index == ++num)
		{
			mlmeOrphanResponse.UserFields.Orphanaddress = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			mlmeOrphanResponse.UserFields.Shortaddress = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeOrphanResponse.UserFields.Associatedmember = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeOrphanResponse.UserFields.Securitylevel = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeOrphanResponse.UserFields.Keyidmode = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeOrphanResponse.UserFields.Keysource = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			mlmeOrphanResponse.UserFields.Keyindex = Convert.ToUInt32(value, 16);
		}
	}
}
