using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FM.Packets;

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

	public override string DisplayGroup => "Test";

	public BlockPeekInfo(BlockPeek packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		BlockPeek blockPeek = (BlockPeek)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Register Address", RegisterMapInfo.RegisterMapToDescription(), 8, FormatValue(blockPeek.UserFields.RegisterAddress, 8), RegisterMapInfo.RegisterMapToString(RegisterMapInfo.ValueToRegisterMap(blockPeek.UserFields.RegisterAddress)), "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Memory Control", "Read from memory", 1, FormatValue(blockPeek.UserFields.MemoryControl, 1), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Memory Access", "Memory access XFR mode", 1, FormatValue(blockPeek.UserFields.MemoryAccess, 1), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Read Status", "Read only field", 1, FormatValue(blockPeek.UserFields.ReadStatus, 1), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Length", "Length", 4, FormatValue(blockPeek.UserFields.Length, 4), "", "", "F", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Memory Mode", "Block memory access", 1, FormatValue(blockPeek.UserFields.MemoryMode, 1), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Address", "", 16, FormatValue(blockPeek.UserFields.Address, 16), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		BlockPeek blockPeek = (BlockPeek)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field RegisterAddress");
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field MemoryControl");
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field MemoryAccess");
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field ReadStatus");
		}
		if (index == ++num)
		{
			blockPeek.UserFields.Length = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field MemoryMode");
		}
		if (index == ++num)
		{
			blockPeek.UserFields.Address = Convert.ToUInt32(value, 16);
		}
	}
}
