using System;
using QCRPG.Framework;

namespace QCRPG.TSL.ZigBee.Packets;

public class MlmeDisassociateIndicationInfo : PacketInfoBase
{
	public override string Name => "Mlme Disassociate Indication";

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

	public MlmeDisassociateIndicationInfo(MlmeDisassociateIndication packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		MlmeDisassociateIndication mlmeDisassociateIndication = (MlmeDisassociateIndication)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("PacketLength", "", 32, FormatValue(mlmeDisassociateIndication.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(mlmeDisassociateIndication.UserFields.Protocolid, 8), ProtocolIdInfo.ProtocolIdToString(ProtocolIdInfo.ValueToProtocolId(mlmeDisassociateIndication.UserFields.Protocolid)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Event Code", CommandOpcodeInfo.CommandOpcodeToDescription(), 8, FormatValue(mlmeDisassociateIndication.UserFields.EventCode, 8), CommandOpcodeInfo.CommandOpcodeToString(CommandOpcodeInfo.ValueToCommandOpcode(mlmeDisassociateIndication.UserFields.EventCode)), "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Length", "Payload Length", 16, FormatValue(mlmeDisassociateIndication.UserFields.Length, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("DeviceAddress", "The short device address allocated by the coordinator on successful association. This parameter will be equal to 0xffff if the association attempt was unsuccessful", 64, FormatValue(mlmeDisassociateIndication.UserFields.Deviceaddress, 64), "", "0000", "0xFFFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("DisassociateReason", "The reason for the disassociation\r\n\r\n" + MlmeDisassociateIndication.UserFieldsWrapper.DisassociatereasonInfo.DisassociatereasonToDescription(), 8, FormatValue(mlmeDisassociateIndication.UserFields.Disassociatereason, 8), MlmeDisassociateIndication.UserFieldsWrapper.DisassociatereasonInfo.DisassociatereasonToString(MlmeDisassociateIndication.UserFieldsWrapper.DisassociatereasonInfo.ValueToDisassociatereason(mlmeDisassociateIndication.UserFields.Disassociatereason)), "00", "FF", 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(mlmeDisassociateIndication.UserFields.Securitylevel, 8), SecurityLevelOptionsInfo.SecurityLevelOptionsToString(SecurityLevelOptionsInfo.ValueToSecurityLevelOptions(mlmeDisassociateIndication.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(mlmeDisassociateIndication.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(mlmeDisassociateIndication.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(mlmeDisassociateIndication.UserFields.Keyindex, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		MlmeDisassociateIndication mlmeDisassociateIndication = (MlmeDisassociateIndication)packet;
		int num = -1;
		if (index == ++num)
		{
			mlmeDisassociateIndication.UserFields.Packetlength = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			mlmeDisassociateIndication.UserFields.Protocolid = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field EventCode");
		}
		if (index == ++num)
		{
			mlmeDisassociateIndication.UserFields.Length = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeDisassociateIndication.UserFields.Deviceaddress = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			mlmeDisassociateIndication.UserFields.Disassociatereason = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeDisassociateIndication.UserFields.Securitylevel = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeDisassociateIndication.UserFields.Keyidmode = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeDisassociateIndication.UserFields.Keysource = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			mlmeDisassociateIndication.UserFields.Keyindex = Convert.ToUInt32(value, 16);
		}
	}
}
