using System;
using QCRPG.Framework;

namespace QCRPG.TSL.NFC.Packets;

public class RfDiscoverNtfInfo : PacketInfoBase
{
	public override string Name => "Rf Discover Ntf";

	public override string DisplayGroup => "RF Management";

	public RfDiscoverNtfInfo(RfDiscoverNtf packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		RfDiscoverNtf rfDiscoverNtf = (RfDiscoverNtf)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("RF Discovery ID", RfDiscoveryIdInfo.RfDiscoveryIdToDescription(), 8, FormatValue(rfDiscoverNtf.UserFields.RfDiscoveryId, 8), RfDiscoveryIdInfo.RfDiscoveryIdToString(RfDiscoveryIdInfo.ValueToRfDiscoveryId(rfDiscoverNtf.UserFields.RfDiscoveryId)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("RF Protocol", RfProtocolsInfo.RfProtocolsToDescription(), 8, FormatValue(rfDiscoverNtf.UserFields.RfProtocol, 8), RfProtocolsInfo.RfProtocolsToString(RfProtocolsInfo.ValueToRfProtocols(rfDiscoverNtf.UserFields.RfProtocol)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("RF Technology and Mode", RfTechnologyAndModeInfo.RfTechnologyAndModeToDescription(), 8, FormatValue(rfDiscoverNtf.UserFields.RfTechnologyAndMode, 8), RfTechnologyAndModeInfo.RfTechnologyAndModeToString(RfTechnologyAndModeInfo.ValueToRfTechnologyAndMode(rfDiscoverNtf.UserFields.RfTechnologyAndMode)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Length of RF Technology Specific Parameters", "The length of RF Technology Specific Parameters field to follow.", 8, FormatValue(rfDiscoverNtf.UserFields.LengthOfRfTechnologySpecificParameters, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("RF Technology Specific Parameters", "Depends on poll mode.", rfDiscoverNtf.UserFields.RfTechnologySpecificParametersList.Count * 8, FormatValue(rfDiscoverNtf.UserFields.RfTechnologySpecificParametersList, rfDiscoverNtf.UserFields.RfTechnologySpecificParametersList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Notification Type", RfDiscoverNtf.UserFieldsWrapper.NotificationTypeInfo.NotificationTypeToDescription(), 8, FormatValue(rfDiscoverNtf.UserFields.NotificationType, 8), RfDiscoverNtf.UserFieldsWrapper.NotificationTypeInfo.NotificationTypeToString(RfDiscoverNtf.UserFieldsWrapper.NotificationTypeInfo.ValueToNotificationType(rfDiscoverNtf.UserFields.NotificationType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		RfDiscoverNtf rfDiscoverNtf = (RfDiscoverNtf)packet;
		int num = -1;
		if (index == ++num)
		{
			rfDiscoverNtf.UserFields.RfDiscoveryId = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			rfDiscoverNtf.UserFields.RfProtocol = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			rfDiscoverNtf.UserFields.RfTechnologyAndMode = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			rfDiscoverNtf.UserFields.LengthOfRfTechnologySpecificParameters = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, rfDiscoverNtf.UserFields.RfTechnologySpecificParametersList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				rfDiscoverNtf.UserFields.RfTechnologySpecificParametersList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
		if (index == ++num)
		{
			rfDiscoverNtf.UserFields.NotificationType = Convert.ToUInt32(value, 16);
		}
	}
}
