using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeSetConnectionlessSupplementalTransmitParametersInfo : PacketInfoBase
{
	public override string Name => "Le Set Connectionless Supplemental Transmit Parameters";

	public override string DisplayGroup => "LE Controller";

	public LeSetConnectionlessSupplementalTransmitParametersInfo(LeSetConnectionlessSupplementalTransmitParameters packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeSetConnectionlessSupplementalTransmitParameters leSetConnectionlessSupplementalTransmitParameters = (LeSetConnectionlessSupplementalTransmitParameters)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Advertising_Handle", "Used to identify an advertising set", 8, FormatValue(leSetConnectionlessSupplementalTransmitParameters.UserFields.AdvertisingHandle, 8), "", "00", "EF", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Supplemental_Length", LeSetConnectionlessSupplementalTransmitParameters.UserFieldsWrapper.SupplementalLengthInfo.SupplementalLengthToDescription(), 8, FormatValue(leSetConnectionlessSupplementalTransmitParameters.UserFields.SupplementalLength, 8), LeSetConnectionlessSupplementalTransmitParameters.UserFieldsWrapper.SupplementalLengthInfo.SupplementalLengthToString(LeSetConnectionlessSupplementalTransmitParameters.UserFieldsWrapper.SupplementalLengthInfo.ValueToSupplementalLength(leSetConnectionlessSupplementalTransmitParameters.UserFields.SupplementalLength)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Supplemental_Type", AodSupplementalTypeInfo.AodSupplementalTypeToDescription(), 8, FormatValue(leSetConnectionlessSupplementalTransmitParameters.UserFields.SupplementalType, 8), AodSupplementalTypeInfo.AodSupplementalTypeToString(AodSupplementalTypeInfo.ValueToAodSupplementalType(leSetConnectionlessSupplementalTransmitParameters.UserFields.SupplementalType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("CTE_Count", "The number of Constant Tone Extensions to transmit in each periodic advertising interval", 8, FormatValue(leSetConnectionlessSupplementalTransmitParameters.UserFields.CteCount, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Number_Of_Antenna_IDs", "The number of antenna IDs in the pattern. The Host shall define the Antenna IDs from 0 to N, where N-1 is equal to the total number of antenna elements.", 8, FormatValue(leSetConnectionlessSupplementalTransmitParameters.UserFields.NumberOfAntennaIds, 8), "", "01", "4B", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < leSetConnectionlessSupplementalTransmitParameters.UserFields.AntennaIdsSetList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Antenna_IDs[" + i + "]", "", 8, FormatValue(leSetConnectionlessSupplementalTransmitParameters.UserFields.AntennaIdsSetList[i].AntennaIds, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeSetConnectionlessSupplementalTransmitParameters leSetConnectionlessSupplementalTransmitParameters = (LeSetConnectionlessSupplementalTransmitParameters)packet;
		int num = -1;
		if (index == ++num)
		{
			leSetConnectionlessSupplementalTransmitParameters.UserFields.AdvertisingHandle = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leSetConnectionlessSupplementalTransmitParameters.UserFields.SupplementalLength = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leSetConnectionlessSupplementalTransmitParameters.UserFields.SupplementalType = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leSetConnectionlessSupplementalTransmitParameters.UserFields.CteCount = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leSetConnectionlessSupplementalTransmitParameters.UserFields.NumberOfAntennaIds = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < leSetConnectionlessSupplementalTransmitParameters.UserFields.AntennaIdsSetList.Count; i++)
		{
			if (index == ++num)
			{
				leSetConnectionlessSupplementalTransmitParameters.UserFields.AntennaIdsSetList[i].AntennaIds = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
