using System;
using QCRPG.Framework;

namespace QCRPG.TSL.ZigBee.Packets;

public class VsNvmGetConfirmationInfo : PacketInfoBase
{
	public override string Name => "Vs Nvm Get Confirmation";

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

	public VsNvmGetConfirmationInfo(VsNvmGetConfirmation packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		VsNvmGetConfirmation vsNvmGetConfirmation = (VsNvmGetConfirmation)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("PacketLength", "", 32, FormatValue(vsNvmGetConfirmation.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(vsNvmGetConfirmation.UserFields.Protocolid, 8), ProtocolIdInfo.ProtocolIdToString(ProtocolIdInfo.ValueToProtocolId(vsNvmGetConfirmation.UserFields.Protocolid)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Event Code", CommandOpcodeInfo.CommandOpcodeToDescription(), 8, FormatValue(vsNvmGetConfirmation.UserFields.EventCode, 8), CommandOpcodeInfo.CommandOpcodeToString(CommandOpcodeInfo.ValueToCommandOpcode(vsNvmGetConfirmation.UserFields.EventCode)), "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Length", "Payload Length", 16, FormatValue(vsNvmGetConfirmation.UserFields.Length, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", "Status\r\n\r\n" + ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(vsNvmGetConfirmation.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(vsNvmGetConfirmation.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("NVMTag", "", 16, FormatValue(vsNvmGetConfirmation.UserFields.Nvmtag, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("NVMLength", "", 16, FormatValue(vsNvmGetConfirmation.UserFields.Nvmlength, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("NVMValue", "", vsNvmGetConfirmation.UserFields.NvmvalueList.Count * 8, FormatValue(vsNvmGetConfirmation.UserFields.NvmvalueList, vsNvmGetConfirmation.UserFields.NvmvalueList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		VsNvmGetConfirmation vsNvmGetConfirmation = (VsNvmGetConfirmation)packet;
		int num = -1;
		if (index == ++num)
		{
			vsNvmGetConfirmation.UserFields.Packetlength = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			vsNvmGetConfirmation.UserFields.Protocolid = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field EventCode");
		}
		if (index == ++num)
		{
			vsNvmGetConfirmation.UserFields.Length = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			vsNvmGetConfirmation.UserFields.Status = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			vsNvmGetConfirmation.UserFields.Nvmtag = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			vsNvmGetConfirmation.UserFields.Nvmlength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, vsNvmGetConfirmation.UserFields.NvmvalueList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				vsNvmGetConfirmation.UserFields.NvmvalueList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
