using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

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

	public override string DisplayGroup => "Link Control";

	public ConnectionCompleteInfo(ConnectionComplete packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		ConnectionComplete connectionComplete = (ConnectionComplete)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(connectionComplete.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(connectionComplete.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.  The connection handle is used as an identifier for transmitting and receiving voice data.", 16, FormatValue(connectionComplete.UserFields.ConnectionHandle, 16), "", "", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("BD_ADDR", "", 48, FormatValue(connectionComplete.UserFields.BdAddr, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Link Type", ConnectionComplete.UserFieldsWrapper.LinkTypeInfo.LinkTypeToDescription(), 8, FormatValue(connectionComplete.UserFields.LinkType, 8), ConnectionComplete.UserFieldsWrapper.LinkTypeInfo.LinkTypeToString(ConnectionComplete.UserFieldsWrapper.LinkTypeInfo.ValueToLinkType(connectionComplete.UserFields.LinkType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Encryption Enabled", ConnectionComplete.UserFieldsWrapper.EncryptionEnabledInfo.EncryptionEnabledToDescription(), 8, FormatValue(connectionComplete.UserFields.EncryptionEnabled, 8), ConnectionComplete.UserFieldsWrapper.EncryptionEnabledInfo.EncryptionEnabledToString(ConnectionComplete.UserFieldsWrapper.EncryptionEnabledInfo.ValueToEncryptionEnabled(connectionComplete.UserFields.EncryptionEnabled)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		ConnectionComplete connectionComplete = (ConnectionComplete)packet;
		int num = -1;
		if (index == ++num)
		{
			connectionComplete.UserFields.Status = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			connectionComplete.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			connectionComplete.UserFields.BdAddr = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			connectionComplete.UserFields.LinkType = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			connectionComplete.UserFields.EncryptionEnabled = Convert.ToUInt32(value, 16);
		}
	}
}
