using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class SniffSubratingInfo : PacketInfoBase
{
	public override string Name => "Sniff Subrating";

	public override string DisplayGroup => "Link Policy";

	public SniffSubratingInfo(SniffSubrating packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		SniffSubrating sniffSubrating = (SniffSubrating)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Connection_Handle", "Connection_Handle to be used to identify a connection. Range: 0x0000-0x0EFF (0x0F00 - 0x0FFF Reserved for future use)", 16, FormatValue(sniffSubrating.UserFields.ConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Maximum_Latency", "The Maximum Latency parameter shall be used to calculate the maximum_sniff subrate that the remote device may use. Default: Tsniff, Latency = N * 0.625 msec (1 Baseband slot), Range for N: 0x0002 - 0xFFFE, Time Range: 1.25msec - 40.9 sec)", 16, FormatValue(sniffSubrating.UserFields.MaximumLatency, 16), ValueTimes0p625MsecExpression.ValueTimes0p625MsecToString(sniffSubrating.UserFields.MaximumLatency), "0002", "FFFE", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Minimum_Remote_Timeout", "Minimum base sniff subrate timeout that the remote device may use. Default: 0x0000, Latency = N * 0.625 msec (1 Baseband slot), Range for N: 0x0000 - 0xFFFE, Time Range: 0 sec - 40.9 sec", 16, FormatValue(sniffSubrating.UserFields.MinimumRemoteTimeout, 16), ValueTimes0p625MsecExpression.ValueTimes0p625MsecToString(sniffSubrating.UserFields.MinimumRemoteTimeout), "0000", "FFFE", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Minimum_Local_Timeout", "Minimum base sniff subrate timeout that the local device may use. Default: 0x0000, Latency = N * 0.625 msec (1 Baseband slot), Range for N: 0x0000 - 0xFFFE, Time Range: 0 sec - 40.9 sec", 16, FormatValue(sniffSubrating.UserFields.MinimumLocalTimeout, 16), ValueTimes0p625MsecExpression.ValueTimes0p625MsecToString(sniffSubrating.UserFields.MinimumLocalTimeout), "0000", "FFFE", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		SniffSubrating sniffSubrating = (SniffSubrating)packet;
		int num = -1;
		if (index == ++num)
		{
			sniffSubrating.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			sniffSubrating.UserFields.MaximumLatency = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			sniffSubrating.UserFields.MinimumRemoteTimeout = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			sniffSubrating.UserFields.MinimumLocalTimeout = Convert.ToUInt32(value, 16);
		}
	}
}
