using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeSetPeriodicAdvertisingParametersInfo : PacketInfoBase
{
	public override string Name => "Le Set Periodic Advertising Parameters";

	public override string DisplayGroup => "LE Controller";

	public LeSetPeriodicAdvertisingParametersInfo(LeSetPeriodicAdvertisingParameters packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeSetPeriodicAdvertisingParameters leSetPeriodicAdvertisingParameters = (LeSetPeriodicAdvertisingParameters)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Advertising_Handle", "Used to identify a periodic advertisement", 8, FormatValue(leSetPeriodicAdvertisingParameters.UserFields.AdvertisingHandle, 8), "", "00", "EF", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Periodic_Advertising_Interval_Min", "Minimum advertising interval for periodic advertising. Range: 0x0006 to 0xFFFF. Time = N * 1.25 ms, Time Range: 7.5 ms to 81.91875 s", 16, FormatValue(leSetPeriodicAdvertisingParameters.UserFields.PeriodicAdvertisingIntervalMin, 16), ValueTimes1p25MsecExpression.ValueTimes1p25MsecToString(leSetPeriodicAdvertisingParameters.UserFields.PeriodicAdvertisingIntervalMin), "0006", "FFFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Periodic_Advertising_Interval_Max", "Maximum advertising interval for periodic advertising. Range: 0x0006 to 0xFFFF. Time = N * 1.25 ms, Time Range: 7.5 ms to 81.91875 s", 16, FormatValue(leSetPeriodicAdvertisingParameters.UserFields.PeriodicAdvertisingIntervalMax, 16), ValueTimes1p25MsecExpression.ValueTimes1p25MsecToString(leSetPeriodicAdvertisingParameters.UserFields.PeriodicAdvertisingIntervalMax), "0006", "FFFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Periodic_Advertising_Properties", LeSetPeriodicAdvertisingParameters.UserFieldsWrapper.PeriodicAdvertisingPropertiesInfo.PeriodicAdvertisingPropertiesToDescription(), 16, FormatValue(leSetPeriodicAdvertisingParameters.UserFields.PeriodicAdvertisingProperties, 16), LeSetPeriodicAdvertisingParameters.UserFieldsWrapper.PeriodicAdvertisingPropertiesInfo.PeriodicAdvertisingPropertiesToString(LeSetPeriodicAdvertisingParameters.UserFieldsWrapper.PeriodicAdvertisingPropertiesInfo.ValueToPeriodicAdvertisingProperties(leSetPeriodicAdvertisingParameters.UserFields.PeriodicAdvertisingProperties)), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeSetPeriodicAdvertisingParameters leSetPeriodicAdvertisingParameters = (LeSetPeriodicAdvertisingParameters)packet;
		int num = -1;
		if (index == ++num)
		{
			leSetPeriodicAdvertisingParameters.UserFields.AdvertisingHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leSetPeriodicAdvertisingParameters.UserFields.PeriodicAdvertisingIntervalMin = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leSetPeriodicAdvertisingParameters.UserFields.PeriodicAdvertisingIntervalMax = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leSetPeriodicAdvertisingParameters.UserFields.PeriodicAdvertisingProperties = Convert.ToUInt32(value, 16);
		}
	}
}
