using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LastMemoryDataInfo : PacketInfoBase
{
	public override string Name => "Last Memory Data";

	public override string DisplayGroup => "Vendor Specific";

	public LastMemoryDataInfo(LastMemoryData packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LastMemoryData lastMemoryData = (LastMemoryData)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("wlist_bd", "", 48, FormatValue(lastMemoryData.UserFields.WlistBd, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("AV_bd", "", 48, FormatValue(lastMemoryData.UserFields.AvBd, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("pscan_interval", "", 16, FormatValue(lastMemoryData.UserFields.PscanInterval, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("pscan_window_size", "", 16, FormatValue(lastMemoryData.UserFields.PscanWindowSize, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("pscan_mode", "", 8, FormatValue(lastMemoryData.UserFields.PscanMode, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("LE_ADV_Data", "", lastMemoryData.UserFields.LeAdvDataList.Count * 8, FormatValue(lastMemoryData.UserFields.LeAdvDataList, lastMemoryData.UserFields.LeAdvDataList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("LE_ADV_Data_Length", "", 8, FormatValue(lastMemoryData.UserFields.LeAdvDataLength, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LastMemoryData lastMemoryData = (LastMemoryData)packet;
		int num = -1;
		if (index == ++num)
		{
			lastMemoryData.UserFields.WlistBd = Convert.ToUInt64(value, 16);
			return;
		}
		if (index == ++num)
		{
			lastMemoryData.UserFields.AvBd = Convert.ToUInt64(value, 16);
			return;
		}
		if (index == ++num)
		{
			lastMemoryData.UserFields.PscanInterval = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			lastMemoryData.UserFields.PscanWindowSize = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			lastMemoryData.UserFields.PscanMode = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, lastMemoryData.UserFields.LeAdvDataList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				lastMemoryData.UserFields.LeAdvDataList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
		if (index == ++num)
		{
			lastMemoryData.UserFields.LeAdvDataLength = Convert.ToUInt32(value, 16);
		}
	}
}
