using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeSetScanResponseDataInfo : PacketInfoBase
{
	public override string Name => "Le Set Scan Response Data";

	public override string DisplayGroup => "LE Controller";

	public LeSetScanResponseDataInfo(LeSetScanResponseData packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeSetScanResponseData leSetScanResponseData = (LeSetScanResponseData)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Scan_Response_Data_Length", "The number of significant octets in the Scan_Response_Data", 8, FormatValue(leSetScanResponseData.UserFields.ScanResponseDataLength, 8), "", "00", "1F", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Scan_Response_Data", "31 octets of Scan_Response_Data formatted as defined in BT Specification (ADVERTISING AND SCAN RESPONSE DATA FORMAT Section). All octets zero (default).", leSetScanResponseData.UserFields.ScanResponseDataList.Count * 8, FormatValue(leSetScanResponseData.UserFields.ScanResponseDataList, leSetScanResponseData.UserFields.ScanResponseDataList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.LeftAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeSetScanResponseData leSetScanResponseData = (LeSetScanResponseData)packet;
		int num = -1;
		if (index == ++num)
		{
			leSetScanResponseData.UserFields.ScanResponseDataLength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, leSetScanResponseData.UserFields.ScanResponseDataList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				leSetScanResponseData.UserFields.ScanResponseDataList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
