using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class PastDebugEventInfo : PacketInfoBase
{
	public override string Name => "Past Debug Event";

	public override string DisplayGroup => "Vendor Specific";

	public PastDebugEventInfo(PastDebugEvent packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		PastDebugEvent pastDebugEvent = (PastDebugEvent)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Sub_Opcode", "", 8, FormatValue(pastDebugEvent.UserFields.SubOpcode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("opcode", "", 8, FormatValue(pastDebugEvent.UserFields.Opcode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("length", "", 8, FormatValue(pastDebugEvent.UserFields.Length, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Sevice_Data", "", 16, FormatValue(pastDebugEvent.UserFields.SeviceData, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Sid", "", 8, FormatValue(pastDebugEvent.UserFields.Sid, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Addr_Type", "", 8, FormatValue(pastDebugEvent.UserFields.AddrType, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Phy", "", 8, FormatValue(pastDebugEvent.UserFields.Phy, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("pad", "", 8, FormatValue(pastDebugEvent.UserFields.Pad, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("syncInfo", "", pastDebugEvent.UserFields.SyncinfoList.Count * 8, FormatValue(pastDebugEvent.UserFields.SyncinfoList, pastDebugEvent.UserFields.SyncinfoList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("connEventCounter", "", 16, FormatValue(pastDebugEvent.UserFields.Conneventcounter, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		PastDebugEvent pastDebugEvent = (PastDebugEvent)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubOpcode");
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field Opcode");
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field Length");
		}
		if (index == ++num)
		{
			pastDebugEvent.UserFields.SeviceData = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			pastDebugEvent.UserFields.Sid = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			pastDebugEvent.UserFields.AddrType = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			pastDebugEvent.UserFields.Phy = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			pastDebugEvent.UserFields.Pad = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, pastDebugEvent.UserFields.SyncinfoList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				pastDebugEvent.UserFields.SyncinfoList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
		if (index == ++num)
		{
			pastDebugEvent.UserFields.Conneventcounter = Convert.ToUInt32(value, 16);
		}
	}
}
