using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class TruncatedPageInfo : PacketInfoBase
{
	public override string Name => "Truncated Page";

	public override string DisplayGroup => "Link Control";

	public TruncatedPageInfo(TruncatedPage packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		TruncatedPage truncatedPage = (TruncatedPage)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("BD Address", "BD_ADDR of the Device to page.", 48, FormatValue(truncatedPage.UserFields.BdAddress, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Page_Scan_Repetition_Mode", TruncatedPage.UserFieldsWrapper.PageScanRepetitionModeInfo.PageScanRepetitionModeToDescription(), 8, FormatValue(truncatedPage.UserFields.PageScanRepetitionMode, 8), TruncatedPage.UserFieldsWrapper.PageScanRepetitionModeInfo.PageScanRepetitionModeToString(TruncatedPage.UserFieldsWrapper.PageScanRepetitionModeInfo.ValueToPageScanRepetitionMode(truncatedPage.UserFields.PageScanRepetitionMode)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Clock_Offset", ClockOffsetInfo.ClockOffsetToDescription(), 16, FormatValue(truncatedPage.UserFields.ClockOffset, 16), ClockOffsetInfo.ClockOffsetToString(ClockOffsetInfo.ValueToClockOffset(truncatedPage.UserFields.ClockOffset)), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

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