using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeEnhancedConnectionCompleteInfo : PacketInfoBase
{
	public override string Name => "Le Enhanced Connection Complete";

	public override string DisplayGroup => "LE Controller";

	public LeEnhancedConnectionCompleteInfo(LeEnhancedConnectionComplete packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeEnhancedConnectionComplete leEnhancedConnectionComplete = (LeEnhancedConnectionComplete)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Subevent_Code", "Subevent code for LE Enhanced Connection Complete event", 8, FormatValue(leEnhancedConnectionComplete.UserFields.SubeventCode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(leEnhancedConnectionComplete.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(leEnhancedConnectionComplete.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Connection_Handle", "Connection_Handle. Range: 0x0000-0x0EFF (0x0F00 - 0x0FFF Reserved for future use)", 16, FormatValue(leEnhancedConnectionComplete.UserFields.ConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Role", RoleInfo.RoleToDescription(), 8, FormatValue(leEnhancedConnectionComplete.UserFields.Role, 8), RoleInfo.RoleToString(RoleInfo.ValueToRole(leEnhancedConnectionComplete.UserFields.Role)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Peer_Address_Type", PeerResolvableAddressTypeInfo.PeerResolvableAddressTypeToDescription(), 8, FormatValue(leEnhancedConnectionComplete.UserFields.PeerAddressType, 8), PeerResolvableAddressTypeInfo.PeerResolvableAddressTypeToString(PeerResolvableAddressTypeInfo.ValueToPeerResolvableAddressType(leEnhancedConnectionComplete.UserFields.PeerAddressType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Peer_Address", "Public Device Address, or Random Device Address, Public Identity Address or Random (static) Identity Address of the device to be connected.", 48, FormatValue(leEnhancedConnectionComplete.UserFields.PeerAddress, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Local_Resolvable_Private_Address", "Resolvable Private Address being used by the local device for this connection. This is only valid when the Own_Address_Type (from the HCI_LE_Create_Connection, HCI_LE_Set_Advertising_Parameters, HCI_LE_Set_Extended_Advertising_Parameters, or HCI_LE_Extended_Create_Connection commands) is set to 0x02 or 0x03, and the Controller generated a resolvable private address for the local device using a non-zero local IRK. For other Own_Address_Type values, the Controller shall return all zeros.", 48, FormatValue(leEnhancedConnectionComplete.UserFields.LocalResolvablePrivateAddress, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Peer_Resolvable_Private_Address", "Resolvable Private Address being used by the peer device for this connection. This is only valid for Peer_Address_Type 0x02 and 0x03. For other Peer_Address_Type values, the Controller shall return all zeros.", 48, FormatValue(leEnhancedConnectionComplete.UserFields.PeerResolvablePrivateAddress, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Conn_Interval", "Connection interval used on this connection. Range: 0x0006 to 0x0C80, Time = N * 1.25 ms, Time Range: 7.5 ms to 4000 ms", 16, FormatValue(leEnhancedConnectionComplete.UserFields.ConnInterval, 16), ValueTimes1p25MsecExpression.ValueTimes1p25MsecToString(leEnhancedConnectionComplete.UserFields.ConnInterval), "0006", "0C80", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Conn_Latency", "Slave latency for the connection in number of connection events", 16, FormatValue(leEnhancedConnectionComplete.UserFields.ConnLatency, 16), "", "0000", "01F3", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Supervision_Timeout", "Connection supervision timeout. Range: 0x000A to 0x0C80, Time = N * 10 ms, Time Range: 100 ms to 32 s", 16, FormatValue(leEnhancedConnectionComplete.UserFields.SupervisionTimeout, 16), ValueTimes10MsecExpression.ValueTimes10MsecToString(leEnhancedConnectionComplete.UserFields.SupervisionTimeout), "000A", "0C80", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Master_Clock_Accuracy", ClockAccuracyInfo.ClockAccuracyToDescription(), 8, FormatValue(leEnhancedConnectionComplete.UserFields.MasterClockAccuracy, 8), ClockAccuracyInfo.ClockAccuracyToString(ClockAccuracyInfo.ValueToClockAccuracy(leEnhancedConnectionComplete.UserFields.MasterClockAccuracy)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeEnhancedConnectionComplete leEnhancedConnectionComplete = (LeEnhancedConnectionComplete)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubeventCode");
		}
		if (index == ++num)
		{
			leEnhancedConnectionComplete.UserFields.Status = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leEnhancedConnectionComplete.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leEnhancedConnectionComplete.UserFields.Role = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leEnhancedConnectionComplete.UserFields.PeerAddressType = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leEnhancedConnectionComplete.UserFields.PeerAddress = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			leEnhancedConnectionComplete.UserFields.LocalResolvablePrivateAddress = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			leEnhancedConnectionComplete.UserFields.PeerResolvablePrivateAddress = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			leEnhancedConnectionComplete.UserFields.ConnInterval = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leEnhancedConnectionComplete.UserFields.ConnLatency = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leEnhancedConnectionComplete.UserFields.SupervisionTimeout = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leEnhancedConnectionComplete.UserFields.MasterClockAccuracy = Convert.ToUInt32(value, 16);
		}
	}
}
