using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeApcfSetFilteringParametersInfo : PacketInfoBase
{
	public override string Name => "Le Apcf Set Filtering Parameters";

	public override string DisplayGroup => "Vendor Specific";

	public LeApcfSetFilteringParametersInfo(LeApcfSetFilteringParameters packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeApcfSetFilteringParameters leApcfSetFilteringParameters = (LeApcfSetFilteringParameters)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("APCF_opcode", "APCF Set Filtering Parameters", 8, FormatValue(leApcfSetFilteringParameters.UserFields.ApcfOpcode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("APCF_Action", LeApcfSetFilteringParameters.UserFieldsWrapper.ApcfActionInfo.ApcfActionToDescription(), 8, FormatValue(leApcfSetFilteringParameters.UserFields.ApcfAction, 8), LeApcfSetFilteringParameters.UserFieldsWrapper.ApcfActionInfo.ApcfActionToString(LeApcfSetFilteringParameters.UserFieldsWrapper.ApcfActionInfo.ValueToApcfAction(leApcfSetFilteringParameters.UserFields.ApcfAction)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("APCF_Filter_Index", "Filter index (0, max_filter-1)", 8, FormatValue(leApcfSetFilteringParameters.UserFields.ApcfFilterIndex, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("APCF_Feature_Selection", "Bit masks for the selected features: Bit 0: set to enable Broadcast Address filter, Bit 1: set to enable Service Data Change filter, Bit 2: set to enable Service UUID check, Bit 3: set to enable Service Solicitation UUID check, Bit 4: set to enable Local Name check, Bit 5: set to enable Manufacturer Data Check, Bit 6: set to enable Service Data Check", 16, FormatValue(leApcfSetFilteringParameters.UserFields.ApcfFeatureSelection, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("APCF_List_Logic_Type", "Logic operation for each feature selection (per bit position) specified in APCF_Feature_Selection. Valid only when a feature is enabled. bit position value 0: OR, 1: AND. If “AND” logic is selected, an ADV packet will pass the filter only if it contains ALL of the entries in the list. If “OR” logic is selected, an ADV packet will pass the filter if it contains any of the entries in the list.", 16, FormatValue(leApcfSetFilteringParameters.UserFields.ApcfListLogicType, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("APCF_Filter_Logic_Type", LeApcfSetFilteringParameters.UserFieldsWrapper.ApcfFilterLogicTypeInfo.ApcfFilterLogicTypeToDescription(), 8, FormatValue(leApcfSetFilteringParameters.UserFields.ApcfFilterLogicType, 8), LeApcfSetFilteringParameters.UserFieldsWrapper.ApcfFilterLogicTypeInfo.ApcfFilterLogicTypeToString(LeApcfSetFilteringParameters.UserFieldsWrapper.ApcfFilterLogicTypeInfo.ValueToApcfFilterLogicType(leApcfSetFilteringParameters.UserFields.ApcfFilterLogicType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("rssi_high_thresh", "in dBm, the advertiser is deemed seen ONLY if the signal is higher than rssi high threshold. Otherwise f/w must behave as if it never saw it.", 8, FormatValue(leApcfSetFilteringParameters.UserFields.RssiHighThresh, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("delivery_mode", LeApcfSetFilteringParameters.UserFieldsWrapper.DeliveryModeInfo.DeliveryModeToDescription(), 8, FormatValue(leApcfSetFilteringParameters.UserFields.DeliveryMode, 8), LeApcfSetFilteringParameters.UserFieldsWrapper.DeliveryModeInfo.DeliveryModeToString(LeApcfSetFilteringParameters.UserFieldsWrapper.DeliveryModeInfo.ValueToDeliveryMode(leApcfSetFilteringParameters.UserFields.DeliveryMode)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("onfound_timeout", "(valid only if delivery_mode is on_found) [in millisecond] Time for firmware to linger and collect additional advertisements before reporting", 16, FormatValue(leApcfSetFilteringParameters.UserFields.OnfoundTimeout, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("onfound_timeout_cnt", "(valid only if delivery_mode is on_found) [count] If an advertisement onFound lingers in f/w for onfound_timeout duration, it will collect few advertisement and count is checked. If the count exceeds onfound_timeout_cnt, it’s reported OnFound, immediately thereafter.", 8, FormatValue(leApcfSetFilteringParameters.UserFields.OnfoundTimeoutCnt, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("rssi_low_thresh", "(valid only if delivery_mode is on_found) in dBm the advertiser packet is considered as not seen, if the rssi of the received packet is not above the rssi low threshold", 8, FormatValue(leApcfSetFilteringParameters.UserFields.RssiLowThresh, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("onlost_timeout", "(valid only if delivery_mode is on_found) [in millisecond] An advertisement, after found, is not seen contiguously for lost_timeout period, it will be reported lost. Reporting of lost is immediate.", 16, FormatValue(leApcfSetFilteringParameters.UserFields.OnlostTimeout, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("num_of_tracking_entries", "(valid only if delivery_mode is on_found) [count] Total number of advertisers to track per filter.", 16, FormatValue(leApcfSetFilteringParameters.UserFields.NumOfTrackingEntries, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeApcfSetFilteringParameters leApcfSetFilteringParameters = (LeApcfSetFilteringParameters)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field ApcfOpcode");
		}
		if (index == ++num)
		{
			leApcfSetFilteringParameters.UserFields.ApcfAction = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leApcfSetFilteringParameters.UserFields.ApcfFilterIndex = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leApcfSetFilteringParameters.UserFields.ApcfFeatureSelection = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leApcfSetFilteringParameters.UserFields.ApcfListLogicType = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leApcfSetFilteringParameters.UserFields.ApcfFilterLogicType = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leApcfSetFilteringParameters.UserFields.RssiHighThresh = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leApcfSetFilteringParameters.UserFields.DeliveryMode = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leApcfSetFilteringParameters.UserFields.OnfoundTimeout = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leApcfSetFilteringParameters.UserFields.OnfoundTimeoutCnt = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leApcfSetFilteringParameters.UserFields.RssiLowThresh = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leApcfSetFilteringParameters.UserFields.OnlostTimeout = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leApcfSetFilteringParameters.UserFields.NumOfTrackingEntries = Convert.ToUInt32(value, 16);
		}
	}
}
