using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeDataLengthChangeInfo : PacketInfoBase
{
	public override string Name => "Le Data Length Change";

	public override string DisplayGroup => "LE Controller";

	public LeDataLengthChangeInfo(LeDataLengthChange packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeDataLengthChange leDataLengthChange = (LeDataLengthChange)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Subevent_Code", "Subevent code for LE Data Length Change event", 8, FormatValue(leDataLengthChange.UserFields.SubeventCode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		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(leDataLengthChange.UserFields.ConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Max_Tx_Octets", "The maximum number of payload octets in a Link Layer Data Channel PDU that the local Controller will send on this connection (connEffectiveMaxTxOctets defined in [Vol 6] Part B, Section 4.5.10). Range 0x001B-0x00FB (0x0000 - 0x001A and 0x00FC - 0xFFFF Reserved for future use)", 16, FormatValue(leDataLengthChange.UserFields.MaxTxOctets, 16), "", "001B", "00FB", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Max_Tx_Time", "The maximum time that the local Controller will take to send a Link Layer Data Channel PDU on this connection (connEffectiveMaxTxTime defined in [Vol 6] Part B, Section 4.5.10). Range 0x0148-0x4290 (all other values reserved for future use)", 16, FormatValue(leDataLengthChange.UserFields.MaxTxTime, 16), "", "0148", "4290", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Max_Rx_Octets", "The maximum number of payload octets in a Link Layer Data Channel PDU that the local Controller expects to receive on this connection (connEffectiveMaxRxOctets defined in [Vol 6] Part B, Section 4.5.10). Range 0x001B-0x00FB (0x0000 - 0x001A and 0x00FC - 0xFFFF Reserved for future use)", 16, FormatValue(leDataLengthChange.UserFields.MaxRxOctets, 16), "", "001B", "00FB", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Max_Rx_Time", "The maximum time that the local Controller expects to take to receive a Link Layer Data Channel PDU on this connection (connEffectiveMaxRxTime defined in [Vol 6] Part B, Section 4.5.10). Range 0x0148-0x4290 (all other values reserved for future use)", 16, FormatValue(leDataLengthChange.UserFields.MaxRxTime, 16), "", "0148", "4290", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeDataLengthChange leDataLengthChange = (LeDataLengthChange)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubeventCode");
		}
		if (index == ++num)
		{
			leDataLengthChange.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leDataLengthChange.UserFields.MaxTxOctets = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leDataLengthChange.UserFields.MaxTxTime = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leDataLengthChange.UserFields.MaxRxOctets = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leDataLengthChange.UserFields.MaxRxTime = Convert.ToUInt32(value, 16);
		}
	}
}
