using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class InquiryResultWithRssiInfo : PacketInfoBase
{
	public override string Name => "Inquiry Result With Rssi";

	public override string DisplayGroup => "Link Control";

	public InquiryResultWithRssiInfo(InquiryResultWithRssi packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		InquiryResultWithRssi inquiryResultWithRssi = (InquiryResultWithRssi)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Num Responses", "Number of responses from the inquiry.", 8, FormatValue(inquiryResultWithRssi.UserFields.NumResponses, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < inquiryResultWithRssi.UserFields.ResponseList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("BD_ADDR[" + i + "]", "", 48, FormatValue(inquiryResultWithRssi.UserFields.ResponseList[i].BdAddr, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Page Scan Repetition Mode[" + i + "]", PageScanRepetitionModeInfo.PageScanRepetitionModeToDescription(), 8, FormatValue(inquiryResultWithRssi.UserFields.ResponseList[i].PageScanRepetitionMode, 8), PageScanRepetitionModeInfo.PageScanRepetitionModeToString(PageScanRepetitionModeInfo.ValueToPageScanRepetitionMode(inquiryResultWithRssi.UserFields.ResponseList[i].PageScanRepetitionMode)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Reserved[" + i + "]", "", 8, FormatValue(inquiryResultWithRssi.UserFields.ResponseList[i].Reserved, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Class of Device[" + i + "]", "", 24, FormatValue(inquiryResultWithRssi.UserFields.ResponseList[i].ClassOfDevice, 24), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Clock Offset[" + i + "]", "Bit 14-0 = Bit 16-2 of CLKNslave-CLK, Bit 15 = Reserved", 16, FormatValue(inquiryResultWithRssi.UserFields.ResponseList[i].ClockOffset, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("RSSI[" + i + "]", "Range is -127dBm to +20dBm\r\n\r\n" + InquiryResultWithRssi.ResponseSubField.RssiInfo.RssiToDescription(), 8, FormatValue(inquiryResultWithRssi.UserFields.ResponseList[i].Rssi, 8), InquiryResultWithRssi.ResponseSubField.RssiInfo.RssiToString(InquiryResultWithRssi.ResponseSubField.RssiInfo.ValueToRssi(inquiryResultWithRssi.UserFields.ResponseList[i].Rssi)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		InquiryResultWithRssi inquiryResultWithRssi = (InquiryResultWithRssi)packet;
		int num = -1;
		if (index == ++num)
		{
			inquiryResultWithRssi.UserFields.NumResponses = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < inquiryResultWithRssi.UserFields.ResponseList.Count; i++)
		{
			if (index == ++num)
			{
				inquiryResultWithRssi.UserFields.ResponseList[i].BdAddr = Convert.ToUInt64(value, 16);
				break;
			}
			if (index == ++num)
			{
				inquiryResultWithRssi.UserFields.ResponseList[i].PageScanRepetitionMode = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				inquiryResultWithRssi.UserFields.ResponseList[i].Reserved = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				inquiryResultWithRssi.UserFields.ResponseList[i].ClassOfDevice = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				inquiryResultWithRssi.UserFields.ResponseList[i].ClockOffset = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				inquiryResultWithRssi.UserFields.ResponseList[i].Rssi = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
