using System;
using QCRPG.Framework;

namespace QCRPG.TSL.NFC.Packets;

public class RfT3tPollingNtfInfo : PacketInfoBase
{
	public override string Name => "Rf T3t Polling Ntf";

	public override string DisplayGroup => "RF Management";

	public RfT3tPollingNtfInfo(RfT3tPollingNtf packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		RfT3tPollingNtf rfT3tPollingNtf = (RfT3tPollingNtf)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Status", StatusCodesInfo.StatusCodesToDescription(), 8, FormatValue(rfT3tPollingNtf.UserFields.Status, 8), StatusCodesInfo.StatusCodesToString(StatusCodesInfo.ValueToStatusCodes(rfT3tPollingNtf.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Number of Responses", "The number of Response fields to follow (n).", 8, FormatValue(rfT3tPollingNtf.UserFields.NumberOfResponses, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < rfT3tPollingNtf.UserFields.ResponseList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Length[" + i + "]", "Length of following SENSF_RES field (m). Allowed values SHALL be 0x10 or 0x12. Other values are RFU.", 8, FormatValue(rfT3tPollingNtf.UserFields.ResponseList[i].Length, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("SENSF_RES[" + i + "]", "Byte 2-17/19 of SENSF_RES Response as defined in [DIGITAL].", rfT3tPollingNtf.UserFields.ResponseList[i].SensfResList.Count * 8, FormatValue(rfT3tPollingNtf.UserFields.ResponseList[i].SensfResList, rfT3tPollingNtf.UserFields.ResponseList[i].SensfResList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		RfT3tPollingNtf rfT3tPollingNtf = (RfT3tPollingNtf)packet;
		int num = -1;
		if (index == ++num)
		{
			rfT3tPollingNtf.UserFields.Status = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			rfT3tPollingNtf.UserFields.NumberOfResponses = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < rfT3tPollingNtf.UserFields.ResponseList.Count; i++)
		{
			if (index == ++num)
			{
				rfT3tPollingNtf.UserFields.ResponseList[i].Length = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				value = AddLeadingZerosAndCheckValueStringLength(value, rfT3tPollingNtf.UserFields.ResponseList[i].SensfResList.Count);
				int num2 = 0;
				while (value.Length > 0)
				{
					string value2 = value.Substring(0, 2);
					value = value.Remove(0, 2);
					rfT3tPollingNtf.UserFields.ResponseList[i].SensfResList[num2] = Convert.ToUInt32(value2, 16);
					num2++;
				}
			}
		}
	}
}
