using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class WriteLcRegisterInfo : PacketInfoBase
{
	public override string Name => "Write Lc Register";

	public override string DisplayGroup => "Vendor Specific";

	public WriteLcRegisterInfo(WriteLcRegister packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		WriteLcRegister writeLcRegister = (WriteLcRegister)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("SubOpCode", "HCI_VS_DEBUG_RMC_REG_WRITE_CMD", 8, FormatValue(writeLcRegister.UserFields.Subopcode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Offset", "The offset of based LC Register address", 8, FormatValue(writeLcRegister.UserFields.Offset, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Value", "Register value", 32, FormatValue(writeLcRegister.UserFields.Value, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

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