using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class CsrTxPowerEventInfo : PacketInfoBase
{
	public override string Name => "Csr Tx Power Event";

	public override string DisplayGroup => "Vendor Specific CSR";

	public CsrTxPowerEventInfo(CsrTxPowerEvent packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		CsrTxPowerEvent csrTxPowerEvent = (CsrTxPowerEvent)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("RESERVED", "", 8, FormatValue(csrTxPowerEvent.UserFields.Reserved, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("TYPE", "", 16, FormatValue(csrTxPowerEvent.UserFields.Type, 16), "", "", "", settable: false, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("LENGTH", "", 16, FormatValue(csrTxPowerEvent.UserFields.Length, 16), "", "", "", settable: false, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("SEQNO", "", 16, FormatValue(csrTxPowerEvent.UserFields.Seqno, 16), "", "", "", settable: false, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("VARID", "", 16, FormatValue(csrTxPowerEvent.UserFields.Varid, 16), "", "", "", settable: false, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("STATUS", "", 16, FormatValue(csrTxPowerEvent.UserFields.Status, 16), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("TESTID", "", 16, FormatValue(csrTxPowerEvent.UserFields.Testid, 16), "", "", "", settable: false, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("LVL", "", 16, FormatValue(csrTxPowerEvent.UserFields.Lvl, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("RSVD", "", 32, FormatValue(csrTxPowerEvent.UserFields.Rsvd, 32), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		CsrTxPowerEvent csrTxPowerEvent = (CsrTxPowerEvent)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field Reserved");
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field Type");
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field Length");
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field Seqno");
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field Varid");
		}
		if (index == ++num)
		{
			csrTxPowerEvent.UserFields.Status = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field Testid");
		}
		if (index == ++num)
		{
			csrTxPowerEvent.UserFields.Lvl = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			csrTxPowerEvent.UserFields.Rsvd = Convert.ToUInt32(value, 16);
		}
	}
}
