using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class PokeSsbiRegisterInfo : PacketInfoBase
{
	public override string Name => "Poke Ssbi Register";

	public override string DisplayGroup => "Vendor Specific";

	public PokeSsbiRegisterInfo(PokeSsbiRegister packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		PokeSsbiRegister pokeSsbiRegister = (PokeSsbiRegister)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Sub OpCode", "POKE_SSBI_REGISTER", 8, FormatValue(pokeSsbiRegister.UserFields.SubOpcode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Address", "SSBI register address", 16, FormatValue(pokeSsbiRegister.UserFields.Address, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Value", "SSBI register value", 8, FormatValue(pokeSsbiRegister.UserFields.Value, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		PokeSsbiRegister pokeSsbiRegister = (PokeSsbiRegister)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubOpcode");
		}
		if (index == ++num)
		{
			pokeSsbiRegister.UserFields.Address = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			pokeSsbiRegister.UserFields.Value = Convert.ToUInt32(value, 16);
		}
	}
}
