using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

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

	public override string DisplayGroup => "Link Policy";

	public SniffSubratingEventInfo(SniffSubratingEvent packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		SniffSubratingEvent sniffSubratingEvent = (SniffSubratingEvent)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(sniffSubratingEvent.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(sniffSubratingEvent.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Connection Handle", "Connection_Handle for which the Link Key has been changed for all devices in the same piconet.", 16, FormatValue(sniffSubratingEvent.UserFields.ConnectionHandle, 16), "", "", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Maximum_Transmit_Latency", "Unit: Slots (0.625ms) -  Maximum latency for data being transmitted from the local device to the remote device. Latency = N * 0.625 msec (1 Baseband slot) Range for N: 0x0000 – 0xFFFE Time Range: 0 sec - 40.9 sec", 16, FormatValue(sniffSubratingEvent.UserFields.MaximumTransmitLatency, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Maximum_Receive_Latency", "Unit: Slots (0.625ms) -  Maximum latency for data being transmitted by the local device from the remote device. Latency = N * 0.625 msec (1 Baseband slot) Range for N: 0x0000 – 0xFFFE Time Range: 0 sec - 40.9 sec", 16, FormatValue(sniffSubratingEvent.UserFields.MaximumReceiveLatency, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Minimum_Remote_Timeout", "Unit: Slots (0.625ms) -  The base sniff subrate timeout in baseband slots that the remote device shall use. Timeout = N * 0.625 msec (1 Baseband slot) Range for N: 0x0000 – 0x8000 Time Range: 0 sec – 40.9 sec", 16, FormatValue(sniffSubratingEvent.UserFields.MinimumRemoteTimeout, 16), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Minimum_Local_Timeout", "Unit: Slots (0.625ms) -  The base sniff subrate timeout in baseband slots that the local device will use. Timeout = N * 0.625 msec (1 Baseband slot) Range for N: 0x0000 – 0x8000 Time Range: 0 sec – 40.9 sec", 16, FormatValue(sniffSubratingEvent.UserFields.MinimumLocalTimeout, 16), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		SniffSubratingEvent sniffSubratingEvent = (SniffSubratingEvent)packet;
		int num = -1;
		if (index == ++num)
		{
			sniffSubratingEvent.UserFields.Status = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			sniffSubratingEvent.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			sniffSubratingEvent.UserFields.MaximumTransmitLatency = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			sniffSubratingEvent.UserFields.MaximumReceiveLatency = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			sniffSubratingEvent.UserFields.MinimumRemoteTimeout = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			sniffSubratingEvent.UserFields.MinimumLocalTimeout = Convert.ToUInt32(value, 16);
		}
	}
}
