using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class SynchronousConnectionCompleteInfo : PacketInfoBase
{
	public override string Name => "Synchronous Connection Complete";

	public override string DisplayGroup => "Link Control";

	public SynchronousConnectionCompleteInfo(SynchronousConnectionComplete packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		SynchronousConnectionComplete synchronousConnectionComplete = (SynchronousConnectionComplete)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(synchronousConnectionComplete.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(synchronousConnectionComplete.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(synchronousConnectionComplete.UserFields.ConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("BD_ADDR", "BD_ADDR of the other connected device forming the connection.", 48, FormatValue(synchronousConnectionComplete.UserFields.BdAddr, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Link_Type", SynchronousConnectionComplete.UserFieldsWrapper.LinkTypeInfo.LinkTypeToDescription(), 8, FormatValue(synchronousConnectionComplete.UserFields.LinkType, 8), SynchronousConnectionComplete.UserFieldsWrapper.LinkTypeInfo.LinkTypeToString(SynchronousConnectionComplete.UserFieldsWrapper.LinkTypeInfo.ValueToLinkType(synchronousConnectionComplete.UserFields.LinkType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Transmission_Interval", "Time between two consecutive eSCO instants measured in slots. Must be zero for SCO links.", 8, FormatValue(synchronousConnectionComplete.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 for SCO links.", 8, FormatValue(synchronousConnectionComplete.UserFields.RetransmissionWindow, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Tx_Packet_Length", "Length in bytes of the eSCO payload in the transmit direction. Must be zero for SCO links.", 16, FormatValue(synchronousConnectionComplete.UserFields.TxPacketLength, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Air_Mode", SynchronousConnectionComplete.UserFieldsWrapper.AirModeInfo.AirModeToDescription(), 8, FormatValue(synchronousConnectionComplete.UserFields.AirMode, 8), SynchronousConnectionComplete.UserFieldsWrapper.AirModeInfo.AirModeToString(SynchronousConnectionComplete.UserFieldsWrapper.AirModeInfo.ValueToAirMode(synchronousConnectionComplete.UserFields.AirMode)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		SynchronousConnectionComplete synchronousConnectionComplete = (SynchronousConnectionComplete)packet;
		int num = -1;
		if (index == ++num)
		{
			synchronousConnectionComplete.UserFields.Status = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			synchronousConnectionComplete.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			synchronousConnectionComplete.UserFields.BdAddr = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			synchronousConnectionComplete.UserFields.LinkType = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			synchronousConnectionComplete.UserFields.TransmissionInterval = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			synchronousConnectionComplete.UserFields.RetransmissionWindow = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			synchronousConnectionComplete.UserFields.TxPacketLength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			synchronousConnectionComplete.UserFields.AirMode = Convert.ToUInt32(value, 16);
		}
	}
}
