using System;
using QCRPG.Framework;

namespace QCRPG.TSL.NFC.Packets;

public class CoreConnCreditsNtfInfo : PacketInfoBase
{
	public override string Name => "Core Conn Credits Ntf";

	public override string DisplayGroup => "NCI Core";

	public CoreConnCreditsNtfInfo(CoreConnCreditsNtf packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		CoreConnCreditsNtf coreConnCreditsNtf = (CoreConnCreditsNtf)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Number of Entries", "Number of Entry fields to follow (n).", 8, FormatValue(coreConnCreditsNtf.UserFields.NumberOfEntries, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < coreConnCreditsNtf.UserFields.EntryList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Conn ID[" + i + "]", "The identifier of the Logical Connection for which credits are given. The four least significant bits of the octet SHALL contain the Conn ID as defined in Table 4. The four most significant bits are RFU.", 8, FormatValue(coreConnCreditsNtf.UserFields.EntryList[i].ConnId, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Credits[" + i + "]", "The number of credits given.", 8, FormatValue(coreConnCreditsNtf.UserFields.EntryList[i].Credits, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		CoreConnCreditsNtf coreConnCreditsNtf = (CoreConnCreditsNtf)packet;
		int num = -1;
		if (index == ++num)
		{
			coreConnCreditsNtf.UserFields.NumberOfEntries = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < coreConnCreditsNtf.UserFields.EntryList.Count; i++)
		{
			if (index == ++num)
			{
				coreConnCreditsNtf.UserFields.EntryList[i].ConnId = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				coreConnCreditsNtf.UserFields.EntryList[i].Credits = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
