using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class RemoteNameRequestInfo : PacketInfoBase
{
	public override string Name => "Remote Name Request";

	public override string DisplayGroup => "Link Control";

	public RemoteNameRequestInfo(RemoteNameRequest packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		RemoteNameRequest remoteNameRequest = (RemoteNameRequest)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("BD Address", "BD_ADDR for the device whose name is requested.", 48, FormatValue(remoteNameRequest.UserFields.BdAddress, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Page Scan Repetition Mode", PageScanRepetitionModeInfo.PageScanRepetitionModeToDescription(), 8, FormatValue(remoteNameRequest.UserFields.PageScanRepetitionMode, 8), PageScanRepetitionModeInfo.PageScanRepetitionModeToString(PageScanRepetitionModeInfo.ValueToPageScanRepetitionMode(remoteNameRequest.UserFields.PageScanRepetitionMode)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("RESERVED", "Reserved, Must be set to 00", 8, FormatValue(remoteNameRequest.UserFields.Reserved, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Clock Offset", ClockOffsetInfo.ClockOffsetToDescription(), 16, FormatValue(remoteNameRequest.UserFields.ClockOffset, 16), ClockOffsetInfo.ClockOffsetToString(ClockOffsetInfo.ValueToClockOffset(remoteNameRequest.UserFields.ClockOffset)), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		RemoteNameRequest remoteNameRequest = (RemoteNameRequest)packet;
		int num = -1;
		if (index == ++num)
		{
			remoteNameRequest.UserFields.BdAddress = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			remoteNameRequest.UserFields.PageScanRepetitionMode = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			remoteNameRequest.UserFields.Reserved = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			remoteNameRequest.UserFields.ClockOffset = Convert.ToUInt32(value, 16);
		}
	}
}
