using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

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

	public override string DisplayGroup => "Link Control";

	public ReadRemoteExtendedFeaturesCompleteInfo(ReadRemoteExtendedFeaturesComplete packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		ReadRemoteExtendedFeaturesComplete readRemoteExtendedFeaturesComplete = (ReadRemoteExtendedFeaturesComplete)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(readRemoteExtendedFeaturesComplete.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(readRemoteExtendedFeaturesComplete.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Connection Handle", "The Connection_Handle identifying the device to which the remote features apply.", 16, FormatValue(readRemoteExtendedFeaturesComplete.UserFields.ConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Page Number", ReadRemoteExtendedFeaturesComplete.UserFieldsWrapper.PageNumberInfo.PageNumberToDescription(), 8, FormatValue(readRemoteExtendedFeaturesComplete.UserFields.PageNumber, 8), ReadRemoteExtendedFeaturesComplete.UserFieldsWrapper.PageNumberInfo.PageNumberToString(ReadRemoteExtendedFeaturesComplete.UserFieldsWrapper.PageNumberInfo.ValueToPageNumber(readRemoteExtendedFeaturesComplete.UserFields.PageNumber)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Maximum Page Number", "The highest features page number which contains non-zero bits for the remote device", 8, FormatValue(readRemoteExtendedFeaturesComplete.UserFields.MaximumPageNumber, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		if (readRemoteExtendedFeaturesComplete.UserFields.PageNumber == 0)
		{
			fieldInfoList.Add(new PacketFieldInfo("Extended_LMP_Features", "Bit map of requested page of LMP features. See LMP Part C, Section 3.3, Feature Mask Definition for details.\r\n\r\n" + SupportedFeaturesInfo.SupportedFeaturesToDescription(), 64, FormatValue(readRemoteExtendedFeaturesComplete.UserFields.ExtendedLmpFeatures, 64), SupportedFeaturesInfo.SupportedFeaturesToString(SupportedFeaturesInfo.ValueToSupportedFeatures(readRemoteExtendedFeaturesComplete.UserFields.ExtendedLmpFeatures)), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
		else if (readRemoteExtendedFeaturesComplete.UserFields.PageNumber == 1)
		{
			fieldInfoList.Add(new PacketFieldInfo("Extended_LMP_Features", "Bit map of requested page of LMP features. See LMP Part C, Section 3.3, Feature Mask Definition for details.\r\n\r\n" + ExtendedFeaturesPage1Info.ExtendedFeaturesPage1ToDescription(), 64, FormatValue(readRemoteExtendedFeaturesComplete.UserFields.ExtendedLmpFeatures, 64), ExtendedFeaturesPage1Info.ExtendedFeaturesPage1ToString(ExtendedFeaturesPage1Info.ValueToExtendedFeaturesPage1(readRemoteExtendedFeaturesComplete.UserFields.ExtendedLmpFeatures)), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
		else if (readRemoteExtendedFeaturesComplete.UserFields.PageNumber == 2)
		{
			fieldInfoList.Add(new PacketFieldInfo("Extended_LMP_Features", "Bit map of requested page of LMP features. See LMP Part C, Section 3.3, Feature Mask Definition for details.\r\n\r\n" + ExtendedFeaturesPage2Info.ExtendedFeaturesPage2ToDescription(), 64, FormatValue(readRemoteExtendedFeaturesComplete.UserFields.ExtendedLmpFeatures, 64), ExtendedFeaturesPage2Info.ExtendedFeaturesPage2ToString(ExtendedFeaturesPage2Info.ValueToExtendedFeaturesPage2(readRemoteExtendedFeaturesComplete.UserFields.ExtendedLmpFeatures)), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
		else
		{
			fieldInfoList.Add(new PacketFieldInfo("Extended_LMP_Features", "Bit map of requested page of LMP features. See LMP Part C, Section 3.3, Feature Mask Definition for details.", 64, FormatValue(readRemoteExtendedFeaturesComplete.UserFields.ExtendedLmpFeatures, 64), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		ReadRemoteExtendedFeaturesComplete readRemoteExtendedFeaturesComplete = (ReadRemoteExtendedFeaturesComplete)packet;
		int num = -1;
		if (index == ++num)
		{
			readRemoteExtendedFeaturesComplete.UserFields.Status = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			readRemoteExtendedFeaturesComplete.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			readRemoteExtendedFeaturesComplete.UserFields.PageNumber = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			readRemoteExtendedFeaturesComplete.UserFields.MaximumPageNumber = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			readRemoteExtendedFeaturesComplete.UserFields.ExtendedLmpFeatures = Convert.ToUInt64(value, 16);
		}
	}
}
