using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class SynchronousConnectionChangedInfo : PacketInfoBase
{
	public override string Name => "Synchronous Connection Changed";

	public override string DisplayGroup => "Link Control";

	public SynchronousConnectionChangedInfo(SynchronousConnectionChanged packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		SynchronousConnectionChanged synchronousConnectionChanged = (SynchronousConnectionChanged)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(synchronousConnectionChanged.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(synchronousConnectionChanged.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Connection_Handle", "Connection_Handle to be used to identify a connection between two BR/EDR Controllers.", 16, FormatValue(synchronousConnectionChanged.UserFields.ConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Transmission_Interval", "Time between two consecutive SCO/eSCO instants measured in slots.", 8, FormatValue(synchronousConnectionChanged.UserFields.TransmissionInterval, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Retransmission_Window", "The size of the retransmission window measured in slots. Must be zero forSCO links.", 8, FormatValue(synchronousConnectionChanged.UserFields.RetransmissionWindow, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Rx_Packet_Length", "Length in bytes of the SCO/eSCO payload in the receive direction.", 16, FormatValue(synchronousConnectionChanged.UserFields.RxPacketLength, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Tx_Packet_Length", "Length in bytes of the SCO/eSCO payload in the transmit direction.", 16, FormatValue(synchronousConnectionChanged.UserFields.TxPacketLength, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		SynchronousConnectionChanged synchronousConnectionChanged = (SynchronousConnectionChanged)packet;
		int num = -1;
		if (index == ++num)
		{
			synchronousConnectionChanged.UserFields.Status = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			synchronousConnectionChanged.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			synchronousConnectionChanged.UserFields.TransmissionInterval = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			synchronousConnectionChanged.UserFields.RetransmissionWindow = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			synchronousConnectionChanged.UserFields.RxPacketLength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			synchronousConnectionChanged.UserFields.TxPacketLength = Convert.ToUInt32(value, 16);
		}
	}
}
