using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

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

	public override string DisplayGroup => "LE Controller";

	public LeSetAdvertisingParametersInfo(LeSetAdvertisingParameters packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeSetAdvertisingParameters leSetAdvertisingParameters = (LeSetAdvertisingParameters)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Advertising_Interval_Min", "Minimum advertising interval for undirected and low duty cycle directed advertising. Range: 0x0020 to 0x4000. Default: N = 0x0800 (1.28 second), Time = N * 0.625 msec, Time Range: 20 msec to 10.24 sec", 16, FormatValue(leSetAdvertisingParameters.UserFields.AdvertisingIntervalMin, 16), ValueTimes0p625MsecExpression.ValueTimes0p625MsecToString(leSetAdvertisingParameters.UserFields.AdvertisingIntervalMin), "0020", "4000", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Advertising_Interval_Max", "Maximum advertising interval for undirected and low duty cycle directed advertising. Range: 0x0020 to 0x4000. Default: N = 0x0800 (1.28 second), Time = N * 0.625 msec, Time Range: 20 msec to 10.24 sec", 16, FormatValue(leSetAdvertisingParameters.UserFields.AdvertisingIntervalMax, 16), ValueTimes0p625MsecExpression.ValueTimes0p625MsecToString(leSetAdvertisingParameters.UserFields.AdvertisingIntervalMax), "0020", "4000", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Advertising_Type", AdvertisingTypeInfo.AdvertisingTypeToDescription(), 8, FormatValue(leSetAdvertisingParameters.UserFields.AdvertisingType, 8), AdvertisingTypeInfo.AdvertisingTypeToString(AdvertisingTypeInfo.ValueToAdvertisingType(leSetAdvertisingParameters.UserFields.AdvertisingType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Own_Address_Type", OwnAddressTypeInfo.OwnAddressTypeToDescription(), 8, FormatValue(leSetAdvertisingParameters.UserFields.OwnAddressType, 8), OwnAddressTypeInfo.OwnAddressTypeToString(OwnAddressTypeInfo.ValueToOwnAddressType(leSetAdvertisingParameters.UserFields.OwnAddressType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Peer_Address_Type", PeerAddressTypeInfo.PeerAddressTypeToDescription(), 8, FormatValue(leSetAdvertisingParameters.UserFields.PeerAddressType, 8), PeerAddressTypeInfo.PeerAddressTypeToString(PeerAddressTypeInfo.ValueToPeerAddressType(leSetAdvertisingParameters.UserFields.PeerAddressType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Peer_Address", "Public Device Address or Random Device Address of the device to be connected", 48, FormatValue(leSetAdvertisingParameters.UserFields.PeerAddress, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Advertising_Channel_Map", "00000000b: Reserved for future use, xxxxxxx1b: Channel 37 shall be used, xxxxxx1xb: Channel 38 shall be used, xxxxx1xxb: Channel 39 shall be used, 00000111b: Default (all channels enabled)\r\n\r\n" + AdvertisingChannelMapInfo.AdvertisingChannelMapToDescription(), 8, FormatValue(leSetAdvertisingParameters.UserFields.AdvertisingChannelMap, 8), AdvertisingChannelMapInfo.AdvertisingChannelMapToString(AdvertisingChannelMapInfo.ValueToAdvertisingChannelMap(leSetAdvertisingParameters.UserFields.AdvertisingChannelMap)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Advertising_Filter_Policy", AdvertisingFilterPolicyInfo.AdvertisingFilterPolicyToDescription(), 8, FormatValue(leSetAdvertisingParameters.UserFields.AdvertisingFilterPolicy, 8), AdvertisingFilterPolicyInfo.AdvertisingFilterPolicyToString(AdvertisingFilterPolicyInfo.ValueToAdvertisingFilterPolicy(leSetAdvertisingParameters.UserFields.AdvertisingFilterPolicy)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeSetAdvertisingParameters leSetAdvertisingParameters = (LeSetAdvertisingParameters)packet;
		int num = -1;
		if (index == ++num)
		{
			leSetAdvertisingParameters.UserFields.AdvertisingIntervalMin = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leSetAdvertisingParameters.UserFields.AdvertisingIntervalMax = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leSetAdvertisingParameters.UserFields.AdvertisingType = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leSetAdvertisingParameters.UserFields.OwnAddressType = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leSetAdvertisingParameters.UserFields.PeerAddressType = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leSetAdvertisingParameters.UserFields.PeerAddress = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			leSetAdvertisingParameters.UserFields.AdvertisingChannelMap = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leSetAdvertisingParameters.UserFields.AdvertisingFilterPolicy = Convert.ToUInt32(value, 16);
		}
	}
}
