using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FMHCI.Packets;

public class PokeInfo : PacketInfoBase
{
	public override string Name => "Poke";

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

	public PokeInfo(Poke packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		Poke poke = (Poke)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Number Of Addresses To Write", "Number of addresses to write", 8, FormatValue(poke.UserFields.NumberOfAddressesToWrite, 8), "", "", "15", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < poke.UserFields.AddressAndDataListList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Write Address[" + i + "]", "", 32, FormatValue(poke.UserFields.AddressAndDataListList[i].WriteAddress, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Write Data[" + i + "]", "", 32, FormatValue(poke.UserFields.AddressAndDataListList[i].WriteData, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		Poke poke = (Poke)packet;
		int num = -1;
		if (index == ++num)
		{
			poke.UserFields.NumberOfAddressesToWrite = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < poke.UserFields.AddressAndDataListList.Count; i++)
		{
			if (index == ++num)
			{
				poke.UserFields.AddressAndDataListList[i].WriteAddress = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				poke.UserFields.AddressAndDataListList[i].WriteData = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
