using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

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

	public override string DisplayGroup => "LE Controller";

	public LeSetExtendedAdvertisingEnableInfo(LeSetExtendedAdvertisingEnable packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeSetExtendedAdvertisingEnable leSetExtendedAdvertisingEnable = (LeSetExtendedAdvertisingEnable)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Enable", AdvertisingEnableInfo.AdvertisingEnableToDescription(), 8, FormatValue(leSetExtendedAdvertisingEnable.UserFields.Enable, 8), AdvertisingEnableInfo.AdvertisingEnableToString(AdvertisingEnableInfo.ValueToAdvertisingEnable(leSetExtendedAdvertisingEnable.UserFields.Enable)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Number_of_Sets", LeSetExtendedAdvertisingEnable.UserFieldsWrapper.NumberOfSetsInfo.NumberOfSetsToDescription(), 8, FormatValue(leSetExtendedAdvertisingEnable.UserFields.NumberOfSets, 8), LeSetExtendedAdvertisingEnable.UserFieldsWrapper.NumberOfSetsInfo.NumberOfSetsToString(LeSetExtendedAdvertisingEnable.UserFieldsWrapper.NumberOfSetsInfo.ValueToNumberOfSets(leSetExtendedAdvertisingEnable.UserFields.NumberOfSets)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < leSetExtendedAdvertisingEnable.UserFields.AdvertisingSetsList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Advertising_Handle[" + i + "]", "Used to identify an advertising set", 8, FormatValue(leSetExtendedAdvertisingEnable.UserFields.AdvertisingSetsList[i].AdvertisingHandle, 8), "", "00", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Duration[" + i + "]", "Advertising duration. Range: 0x0001 – 0xFFFF, Time = N * 10 msec\r\n\r\n" + LeSetExtendedAdvertisingEnable.AdvertisingSetsSubField.DurationInfo.DurationToDescription(), 16, FormatValue(leSetExtendedAdvertisingEnable.UserFields.AdvertisingSetsList[i].Duration, 16), ValueTimes10MsecExpression.ValueTimes10MsecToString(leSetExtendedAdvertisingEnable.UserFields.AdvertisingSetsList[i].Duration), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Max_Extended_Advertising_Events[" + i + "]", LeSetExtendedAdvertisingEnable.AdvertisingSetsSubField.MaxExtendedAdvertisingEventsInfo.MaxExtendedAdvertisingEventsToDescription(), 8, FormatValue(leSetExtendedAdvertisingEnable.UserFields.AdvertisingSetsList[i].MaxExtendedAdvertisingEvents, 8), LeSetExtendedAdvertisingEnable.AdvertisingSetsSubField.MaxExtendedAdvertisingEventsInfo.MaxExtendedAdvertisingEventsToString(LeSetExtendedAdvertisingEnable.AdvertisingSetsSubField.MaxExtendedAdvertisingEventsInfo.ValueToMaxExtendedAdvertisingEvents(leSetExtendedAdvertisingEnable.UserFields.AdvertisingSetsList[i].MaxExtendedAdvertisingEvents)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeSetExtendedAdvertisingEnable leSetExtendedAdvertisingEnable = (LeSetExtendedAdvertisingEnable)packet;
		int num = -1;
		if (index == ++num)
		{
			leSetExtendedAdvertisingEnable.UserFields.Enable = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leSetExtendedAdvertisingEnable.UserFields.NumberOfSets = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < leSetExtendedAdvertisingEnable.UserFields.AdvertisingSetsList.Count; i++)
		{
			if (index == ++num)
			{
				leSetExtendedAdvertisingEnable.UserFields.AdvertisingSetsList[i].AdvertisingHandle = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				leSetExtendedAdvertisingEnable.UserFields.AdvertisingSetsList[i].Duration = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				leSetExtendedAdvertisingEnable.UserFields.AdvertisingSetsList[i].MaxExtendedAdvertisingEvents = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
