using System;
using QCRPG.Framework;

namespace QCRPG.TSL.NFCCustom.Packets;

public class NfcBPollModeRfSpecificParametersInfo : PacketInfoBase
{
	public override string Name => "Nfc B Poll Mode Rf Specific Parameters";

	public override string DisplayGroup => "";

	public NfcBPollModeRfSpecificParametersInfo(NfcBPollModeRfSpecificParameters packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		NfcBPollModeRfSpecificParameters nfcBPollModeRfSpecificParameters = (NfcBPollModeRfSpecificParameters)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("SENSB_RES Response Length", "Length of SENSB_RES Response Parameter. Allowed values SHALL be 0x0B and 0x0C. Other values are RFU.", 8, FormatValue(nfcBPollModeRfSpecificParameters.UserFields.SensbResResponseLength, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("SENSB_RES Response", "Byte 2 – Byte 12 or 13 of SENSB_RES as defined in [DIGITAL].", nfcBPollModeRfSpecificParameters.UserFields.SensbResResponseList.Count * 8, FormatValue(nfcBPollModeRfSpecificParameters.UserFields.SensbResResponseList, nfcBPollModeRfSpecificParameters.UserFields.SensbResResponseList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		NfcBPollModeRfSpecificParameters nfcBPollModeRfSpecificParameters = (NfcBPollModeRfSpecificParameters)packet;
		int num = -1;
		if (index == ++num)
		{
			nfcBPollModeRfSpecificParameters.UserFields.SensbResResponseLength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, nfcBPollModeRfSpecificParameters.UserFields.SensbResResponseList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				nfcBPollModeRfSpecificParameters.UserFields.SensbResResponseList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
