using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FMHCI.Packets;

public class PeekInfo : PacketInfoBase
{
	public override string Name => "Peek";

	public override string DisplayGroup => "Production Test Mode";

	public PeekInfo(Peek packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		Peek peek = (Peek)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Number Of Addresses To Read", "Number of addresses to read", 8, FormatValue(peek.UserFields.NumberOfAddressesToRead, 8), "", "", "1F", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < peek.UserFields.AddressListList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Read Address[" + i + "]", "", 32, FormatValue(peek.UserFields.AddressListList[i].ReadAddress, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		Peek peek = (Peek)packet;
		int num = -1;
		if (index == ++num)
		{
			peek.UserFields.NumberOfAddressesToRead = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < peek.UserFields.AddressListList.Count; i++)
		{
			if (index == ++num)
			{
				peek.UserFields.AddressListList[i].ReadAddress = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
