using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

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

	public override string DisplayGroup => "LE Controller";

	public LeSetExtendedScanEnableInfo(LeSetExtendedScanEnable packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeSetExtendedScanEnable leSetExtendedScanEnable = (LeSetExtendedScanEnable)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Enable", LeScanEnableInfo.LeScanEnableToDescription(), 8, FormatValue(leSetExtendedScanEnable.UserFields.Enable, 8), LeScanEnableInfo.LeScanEnableToString(LeScanEnableInfo.ValueToLeScanEnable(leSetExtendedScanEnable.UserFields.Enable)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Filter_Duplicates", LeSetExtendedScanEnable.UserFieldsWrapper.FilterDuplicatesInfo.FilterDuplicatesToDescription(), 8, FormatValue(leSetExtendedScanEnable.UserFields.FilterDuplicates, 8), LeSetExtendedScanEnable.UserFieldsWrapper.FilterDuplicatesInfo.FilterDuplicatesToString(LeSetExtendedScanEnable.UserFieldsWrapper.FilterDuplicatesInfo.ValueToFilterDuplicates(leSetExtendedScanEnable.UserFields.FilterDuplicates)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Duration", "Scan duration. Range: 0x0001 – 0xFFFF, Time = N * 10 ms, Time Range: 10 ms to 655.35 ms\r\n\r\n" + LeSetExtendedScanEnable.UserFieldsWrapper.DurationInfo.DurationToDescription(), 16, FormatValue(leSetExtendedScanEnable.UserFields.Duration, 16), ValueTimes10MsecExpression.ValueTimes10MsecToString(leSetExtendedScanEnable.UserFields.Duration), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Period", "Time interval from when the Controller started its last Scan_Duration until it begins the subsequent Scan_Duration. Range: 0x00001 – 0xFFFF, Time = N * 1.28 sec, Time Range: 1.28 s to 83,884.8 s\r\n\r\n" + LeSetExtendedScanEnable.UserFieldsWrapper.PeriodInfo.PeriodToDescription(), 16, FormatValue(leSetExtendedScanEnable.UserFields.Period, 16), ValueTimes1p28MsecExpression.ValueTimes1p28MsecToString(leSetExtendedScanEnable.UserFields.Period), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeSetExtendedScanEnable leSetExtendedScanEnable = (LeSetExtendedScanEnable)packet;
		int num = -1;
		if (index == ++num)
		{
			leSetExtendedScanEnable.UserFields.Enable = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leSetExtendedScanEnable.UserFields.FilterDuplicates = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leSetExtendedScanEnable.UserFields.Duration = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leSetExtendedScanEnable.UserFields.Period = Convert.ToUInt32(value, 16);
		}
	}
}
