using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class FlowSubratingInfo : PacketInfoBase
{
	public override string Name => "Flow Subrating";

	public override string DisplayGroup => "Link Policy";

	public FlowSubratingInfo(FlowSubrating packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		FlowSubrating flowSubrating = (FlowSubrating)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(flowSubrating.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(flowSubrating.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Connection Handle", "Connection_Handle. Range: 0x0000-0x0EFF (0x0F00 - 0x0FFF Reserved for future use)", 16, FormatValue(flowSubrating.UserFields.ConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Maximum_Transmit_Latency", "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(flowSubrating.UserFields.MaximumTransmitLatency, 16), "", "0000", "FFFE", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Maximum_Receive_Latency", "Maximum latency for data being received 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(flowSubrating.UserFields.MaximumReceiveLatency, 16), "", "0000", "FFFE", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Minimum_Remote_Timeout", "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(flowSubrating.UserFields.MinimumRemoteTimeout, 16), "", "0000", "8000", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Minimum_Local_Timeout", "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(flowSubrating.UserFields.MinimumLocalTimeout, 16), "", "0000", "8000", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

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