using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class NvmAccessGetEventInfo : PacketInfoBase
{
	public override string Name => "Nvm Access Get Event";

	public override string DisplayGroup => "Vendor Specific";

	public NvmAccessGetEventInfo(NvmAccessGetEvent packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		NvmAccessGetEvent nvmAccessGetEvent = (NvmAccessGetEvent)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Command Class", "", 8, FormatValue(nvmAccessGetEvent.UserFields.CommandClass, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("NVM Command", "", 8, FormatValue(nvmAccessGetEvent.UserFields.NvmCommand, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Tag Number", "", 8, FormatValue(nvmAccessGetEvent.UserFields.TagNumber, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Length", "", 8, FormatValue(nvmAccessGetEvent.UserFields.Length, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Tag Value", "", nvmAccessGetEvent.UserFields.TagValueList.Count * 8, FormatValue(nvmAccessGetEvent.UserFields.TagValueList, nvmAccessGetEvent.UserFields.TagValueList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		NvmAccessGetEvent nvmAccessGetEvent = (NvmAccessGetEvent)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field CommandClass");
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field NvmCommand");
		}
		if (index == ++num)
		{
			nvmAccessGetEvent.UserFields.TagNumber = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			nvmAccessGetEvent.UserFields.Length = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, nvmAccessGetEvent.UserFields.TagValueList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				nvmAccessGetEvent.UserFields.TagValueList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
