using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeRemoteConnectionParameterRequestReplyInfo : PacketInfoBase
{
	public override string Name => "Le Remote Connection Parameter Request Reply";

	public override string DisplayGroup => "LE Controller";

	public LeRemoteConnectionParameterRequestReplyInfo(LeRemoteConnectionParameterRequestReply packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeRemoteConnectionParameterRequestReply leRemoteConnectionParameterRequestReply = (LeRemoteConnectionParameterRequestReply)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Connection_Handle", "Connection_Handle to be used to identify a connection. Range: 0x0000-0x0EFF. Reserved for future use (0x0F00 - 0x0FFF)", 16, FormatValue(leRemoteConnectionParameterRequestReply.UserFields.ConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Interval_Min", "Minimum value of the connection interval. Range: 0x0006 to 0x0C80, Time = N * 1.25 msec, Time Range: 7.5 msec to 4 seconds", 16, FormatValue(leRemoteConnectionParameterRequestReply.UserFields.IntervalMin, 16), "", "0006", "0C80", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Interval_Max", "Maximum value of the connection interval. Range: 0x0006 to 0x0C80, Time = N * 1.25 msec, Time Range: 7.5 msec to 4 seconds", 16, FormatValue(leRemoteConnectionParameterRequestReply.UserFields.IntervalMax, 16), "", "0006", "0C80", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Latency", "Maximum allowed slave latency for the connection specified as the number of connection events. Range: 0x0000 to 0x01F3 (499)", 16, FormatValue(leRemoteConnectionParameterRequestReply.UserFields.Latency, 16), "", "0000", "01F3", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Timeout", "Supervision timeout for the connection. Range: 0x000A to 0x0C80, Time = N * 10 msec, Time Range: 100 msec to 32 seconds", 16, FormatValue(leRemoteConnectionParameterRequestReply.UserFields.Timeout, 16), "", "000A", "0C80", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Minimum_CE_Length", "Information parameter about the minimum length of connection event needed for this LE connection. Range: 0x0000 to 0xFFFF, Time = N * 0.625 ms, Time Range: 0 ms to 40.9 seconds", 16, FormatValue(leRemoteConnectionParameterRequestReply.UserFields.MinimumCeLength, 16), "", "0000", "FFFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Maximum_CE_Length", "Information parameter about the maximum length of connection event needed for this LE connection. Range: 0x0000 to 0xFFFF, Time = N * 0.625 ms, Time Range: 0 ms to 40.9 seconds", 16, FormatValue(leRemoteConnectionParameterRequestReply.UserFields.MaximumCeLength, 16), "", "0000", "FFFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeRemoteConnectionParameterRequestReply leRemoteConnectionParameterRequestReply = (LeRemoteConnectionParameterRequestReply)packet;
		int num = -1;
		if (index == ++num)
		{
			leRemoteConnectionParameterRequestReply.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leRemoteConnectionParameterRequestReply.UserFields.IntervalMin = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leRemoteConnectionParameterRequestReply.UserFields.IntervalMax = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leRemoteConnectionParameterRequestReply.UserFields.Latency = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leRemoteConnectionParameterRequestReply.UserFields.Timeout = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leRemoteConnectionParameterRequestReply.UserFields.MinimumCeLength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leRemoteConnectionParameterRequestReply.UserFields.MaximumCeLength = Convert.ToUInt32(value, 16);
		}
	}
}
