using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeSetScanParametersInfo : PacketInfoBase
{
	public override string Name => "Le Set Scan Parameters";

	public override string DisplayGroup => "LE Controller";

	public LeSetScanParametersInfo(LeSetScanParameters packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeSetScanParameters leSetScanParameters = (LeSetScanParameters)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("LE_Scan_Type", LeSetScanParameters.UserFieldsWrapper.LeScanTypeInfo.LeScanTypeToDescription(), 8, FormatValue(leSetScanParameters.UserFields.LeScanType, 8), LeSetScanParameters.UserFieldsWrapper.LeScanTypeInfo.LeScanTypeToString(LeSetScanParameters.UserFieldsWrapper.LeScanTypeInfo.ValueToLeScanType(leSetScanParameters.UserFields.LeScanType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("LE_Scan_Interval", "This is defined as the time interval from when the Controller started its last LE scan until it begins the subsequent LE scan, Range: 0x0004 to 0x4000, Default: 0x0010 (10 ms), Time = N * 0.625 ms, Time Range: 2.5 ms to 10.24 s", 16, FormatValue(leSetScanParameters.UserFields.LeScanInterval, 16), ValueTimes0p625MsecExpression.ValueTimes0p625MsecToString(leSetScanParameters.UserFields.LeScanInterval), "0004", "4000", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("LE_Scan_Window", "The duration of the LE scan. LE_Scan_Window shall be less than or equal to LE_Scan_Interval, Range: 0x0004 to 0x4000, Default: 0x0010 (10 ms), Time = N * 0.625 ms, Time Range: 2.5 ms to 10240 ms", 16, FormatValue(leSetScanParameters.UserFields.LeScanWindow, 16), ValueTimes0p625MsecExpression.ValueTimes0p625MsecToString(leSetScanParameters.UserFields.LeScanWindow), "0004", "4000", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Own_Address_Type", OwnAddressTypeInfo.OwnAddressTypeToDescription(), 8, FormatValue(leSetScanParameters.UserFields.OwnAddressType, 8), OwnAddressTypeInfo.OwnAddressTypeToString(OwnAddressTypeInfo.ValueToOwnAddressType(leSetScanParameters.UserFields.OwnAddressType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Scanning_Filter_Policy", ScanningFilterPolicyInfo.ScanningFilterPolicyToDescription(), 8, FormatValue(leSetScanParameters.UserFields.ScanningFilterPolicy, 8), ScanningFilterPolicyInfo.ScanningFilterPolicyToString(ScanningFilterPolicyInfo.ValueToScanningFilterPolicy(leSetScanParameters.UserFields.ScanningFilterPolicy)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeSetScanParameters leSetScanParameters = (LeSetScanParameters)packet;
		int num = -1;
		if (index == ++num)
		{
			leSetScanParameters.UserFields.LeScanType = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leSetScanParameters.UserFields.LeScanInterval = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leSetScanParameters.UserFields.LeScanWindow = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leSetScanParameters.UserFields.OwnAddressType = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leSetScanParameters.UserFields.ScanningFilterPolicy = Convert.ToUInt32(value, 16);
		}
	}
}
