using System;
using QCRPG.Framework;

namespace QCRPG.TSL.ZigBee.Packets;

public class MlmeDisassociateConfirmationInfo : PacketInfoBase
{
	public override string Name => "Mlme Disassociate Confirmation";

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

	public MlmeDisassociateConfirmationInfo(MlmeDisassociateConfirmation packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		MlmeDisassociateConfirmation mlmeDisassociateConfirmation = (MlmeDisassociateConfirmation)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("PacketLength", "", 32, FormatValue(mlmeDisassociateConfirmation.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(mlmeDisassociateConfirmation.UserFields.Protocolid, 8), ProtocolIdInfo.ProtocolIdToString(ProtocolIdInfo.ValueToProtocolId(mlmeDisassociateConfirmation.UserFields.Protocolid)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Event Code", CommandOpcodeInfo.CommandOpcodeToDescription(), 8, FormatValue(mlmeDisassociateConfirmation.UserFields.EventCode, 8), CommandOpcodeInfo.CommandOpcodeToString(CommandOpcodeInfo.ValueToCommandOpcode(mlmeDisassociateConfirmation.UserFields.EventCode)), "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Length", "Payload Length", 16, FormatValue(mlmeDisassociateConfirmation.UserFields.Length, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", "The status of the association attempt\r\n\r\n" + AssociationStatusInfo.AssociationStatusToDescription(), 8, FormatValue(mlmeDisassociateConfirmation.UserFields.Status, 8), AssociationStatusInfo.AssociationStatusToString(AssociationStatusInfo.ValueToAssociationStatus(mlmeDisassociateConfirmation.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("DeviceAddrMode", "Addressing mode\r\n\r\n" + MlmeDisassociateConfirmation.UserFieldsWrapper.DeviceaddrmodeInfo.DeviceaddrmodeToDescription(), 8, FormatValue(mlmeDisassociateConfirmation.UserFields.Deviceaddrmode, 8), MlmeDisassociateConfirmation.UserFieldsWrapper.DeviceaddrmodeInfo.DeviceaddrmodeToString(MlmeDisassociateConfirmation.UserFieldsWrapper.DeviceaddrmodeInfo.ValueToDeviceaddrmode(mlmeDisassociateConfirmation.UserFields.Deviceaddrmode)), "2", "3", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("DevicePANId", "PAN ID", 16, FormatValue(mlmeDisassociateConfirmation.UserFields.Devicepanid, 16), "", "0000", "0xFFFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("DeviceAddress", "The address of the device to which to send the disassociation command", 64, FormatValue(mlmeDisassociateConfirmation.UserFields.Deviceaddress, 64), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		MlmeDisassociateConfirmation mlmeDisassociateConfirmation = (MlmeDisassociateConfirmation)packet;
		int num = -1;
		if (index == ++num)
		{
			mlmeDisassociateConfirmation.UserFields.Packetlength = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			mlmeDisassociateConfirmation.UserFields.Protocolid = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field EventCode");
		}
		if (index == ++num)
		{
			mlmeDisassociateConfirmation.UserFields.Length = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeDisassociateConfirmation.UserFields.Status = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeDisassociateConfirmation.UserFields.Deviceaddrmode = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeDisassociateConfirmation.UserFields.Devicepanid = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeDisassociateConfirmation.UserFields.Deviceaddress = Convert.ToUInt64(value, 16);
		}
	}
}
