using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeSetExtendedAdvertisingDataInfo : PacketInfoBase
{
	public override string Name => "Le Set Extended Advertising Data";

	public override string DisplayGroup => "LE Controller";

	public LeSetExtendedAdvertisingDataInfo(LeSetExtendedAdvertisingData packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeSetExtendedAdvertisingData leSetExtendedAdvertisingData = (LeSetExtendedAdvertisingData)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Advertising_Handle", "Used to identify an advertising set", 8, FormatValue(leSetExtendedAdvertisingData.UserFields.AdvertisingHandle, 8), "", "00", "EF", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Operation", LeSetExtendedAdvertisingData.UserFieldsWrapper.OperationInfo.OperationToDescription(), 8, FormatValue(leSetExtendedAdvertisingData.UserFields.Operation, 8), LeSetExtendedAdvertisingData.UserFieldsWrapper.OperationInfo.OperationToString(LeSetExtendedAdvertisingData.UserFieldsWrapper.OperationInfo.ValueToOperation(leSetExtendedAdvertisingData.UserFields.Operation)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Fragment_Preference", FragmentPreferenceInfo.FragmentPreferenceToDescription(), 8, FormatValue(leSetExtendedAdvertisingData.UserFields.FragmentPreference, 8), FragmentPreferenceInfo.FragmentPreferenceToString(FragmentPreferenceInfo.ValueToFragmentPreference(leSetExtendedAdvertisingData.UserFields.FragmentPreference)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Advertising_Data_Length", "The number of octets in the Advertising Data parameter", 8, FormatValue(leSetExtendedAdvertisingData.UserFields.AdvertisingDataLength, 8), "", "00", "FC", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Advertising_Data", "Advertising data formatted as defined in [Vol 3] Part C, Section 11.", leSetExtendedAdvertisingData.UserFields.AdvertisingDataList.Count * 8, FormatValue(leSetExtendedAdvertisingData.UserFields.AdvertisingDataList, leSetExtendedAdvertisingData.UserFields.AdvertisingDataList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.LeftAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeSetExtendedAdvertisingData leSetExtendedAdvertisingData = (LeSetExtendedAdvertisingData)packet;
		int num = -1;
		if (index == ++num)
		{
			leSetExtendedAdvertisingData.UserFields.AdvertisingHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leSetExtendedAdvertisingData.UserFields.Operation = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leSetExtendedAdvertisingData.UserFields.FragmentPreference = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leSetExtendedAdvertisingData.UserFields.AdvertisingDataLength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, leSetExtendedAdvertisingData.UserFields.AdvertisingDataList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				leSetExtendedAdvertisingData.UserFields.AdvertisingDataList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
