using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeReadRemoteFeaturesCompleteInfo : PacketInfoBase
{
	public override string Name => "Le Read Remote Features Complete";

	public override string DisplayGroup => "LE Controller";

	public LeReadRemoteFeaturesCompleteInfo(LeReadRemoteFeaturesComplete packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeReadRemoteFeaturesComplete leReadRemoteFeaturesComplete = (LeReadRemoteFeaturesComplete)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Subevent_Code", "Subevent code for LE Read Remote Features Complete event", 8, FormatValue(leReadRemoteFeaturesComplete.UserFields.SubeventCode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(leReadRemoteFeaturesComplete.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(leReadRemoteFeaturesComplete.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Connection_Handle", "Connection_Handle. Range: 0x0000-0x0EFF.  Reserved for future use (0x0F00 - 0x0FFF) ", 16, FormatValue(leReadRemoteFeaturesComplete.UserFields.ConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("LE_Features", "Bit Mask List of LE features. See [Vol 6] Part B, Section 4.6.\r\n\r\n" + LeFeaturesInfo.LeFeaturesToDescription(), 64, FormatValue(leReadRemoteFeaturesComplete.UserFields.LeFeatures, 64), LeFeaturesInfo.LeFeaturesToString(LeFeaturesInfo.ValueToLeFeatures(leReadRemoteFeaturesComplete.UserFields.LeFeatures)), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeReadRemoteFeaturesComplete leReadRemoteFeaturesComplete = (LeReadRemoteFeaturesComplete)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubeventCode");
		}
		if (index == ++num)
		{
			leReadRemoteFeaturesComplete.UserFields.Status = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leReadRemoteFeaturesComplete.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leReadRemoteFeaturesComplete.UserFields.LeFeatures = Convert.ToUInt64(value, 16);
		}
	}
}
