using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class CsrRxPktStatsEventInfo : PacketInfoBase
{
	public override string Name => "Csr Rx Pkt Stats Event";

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

	public CsrRxPktStatsEventInfo(CsrRxPktStatsEvent packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		CsrRxPktStatsEvent csrRxPktStatsEvent = (CsrRxPktStatsEvent)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("RESERVED", "", 8, FormatValue(csrRxPktStatsEvent.UserFields.Reserved, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("TYPE", "", 16, FormatValue(csrRxPktStatsEvent.UserFields.Type, 16), "", "", "", settable: false, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("LENGTH", "", 16, FormatValue(csrRxPktStatsEvent.UserFields.Length, 16), "", "", "", settable: false, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("SEQNO", "", 16, FormatValue(csrRxPktStatsEvent.UserFields.Seqno, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("VARID", "", 16, FormatValue(csrRxPktStatsEvent.UserFields.Varid, 16), "", "", "", settable: false, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("STATUS", "", 16, FormatValue(csrRxPktStatsEvent.UserFields.Status, 16), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("PKTS_RECEIVED", "", 16, FormatValue(csrRxPktStatsEvent.UserFields.PktsReceived, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("GOOD_PKTS_RECEIVED", "", 16, FormatValue(csrRxPktStatsEvent.UserFields.GoodPktsReceived, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("CORRECTED_PKTS", "", 16, FormatValue(csrRxPktStatsEvent.UserFields.CorrectedPkts, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("RSSI_VALID", "", 16, FormatValue(csrRxPktStatsEvent.UserFields.RssiValid, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("RSVD", "", csrRxPktStatsEvent.UserFields.RsvdList.Count * 8, FormatValue(csrRxPktStatsEvent.UserFields.RsvdList, csrRxPktStatsEvent.UserFields.RsvdList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		CsrRxPktStatsEvent csrRxPktStatsEvent = (CsrRxPktStatsEvent)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)
		{
			csrRxPktStatsEvent.UserFields.Seqno = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field Varid");
		}
		if (index == ++num)
		{
			csrRxPktStatsEvent.UserFields.Status = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			csrRxPktStatsEvent.UserFields.PktsReceived = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			csrRxPktStatsEvent.UserFields.GoodPktsReceived = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			csrRxPktStatsEvent.UserFields.CorrectedPkts = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			csrRxPktStatsEvent.UserFields.RssiValid = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, csrRxPktStatsEvent.UserFields.RsvdList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				csrRxPktStatsEvent.UserFields.RsvdList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
