using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class ControllerDebugInfoInfo : PacketInfoBase
{
	public override string Name => "Controller Debug Info";

	public override string DisplayGroup => "Vendor Specific";

	public ControllerDebugInfoInfo(ControllerDebugInfo packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		ControllerDebugInfo controllerDebugInfo = (ControllerDebugInfo)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("sub_event_code", "Controller Debug Info", 8, FormatValue(controllerDebugInfo.UserFields.SubEventCode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("debug_block_byte_offset_start", "Debug block byte offset from start", 16, FormatValue(controllerDebugInfo.UserFields.DebugBlockByteOffsetStart, 16), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("last_block", ControllerDebugInfo.UserFieldsWrapper.LastBlockInfo.LastBlockToDescription(), 8, FormatValue(controllerDebugInfo.UserFields.LastBlock, 8), ControllerDebugInfo.UserFieldsWrapper.LastBlockInfo.LastBlockToString(ControllerDebugInfo.UserFieldsWrapper.LastBlockInfo.ValueToLastBlock(controllerDebugInfo.UserFields.LastBlock)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("cur_pay_load_sz", "binary block size in current event.", 16, FormatValue(controllerDebugInfo.UserFields.CurPayLoadSz, 16), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Debug_Data", "Debug data of cur_payload_sz", controllerDebugInfo.UserFields.DebugDataList.Count * 8, FormatValue(controllerDebugInfo.UserFields.DebugDataList, controllerDebugInfo.UserFields.DebugDataList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		ControllerDebugInfo controllerDebugInfo = (ControllerDebugInfo)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubEventCode");
		}
		if (index == ++num)
		{
			controllerDebugInfo.UserFields.DebugBlockByteOffsetStart = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			controllerDebugInfo.UserFields.LastBlock = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			controllerDebugInfo.UserFields.CurPayLoadSz = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, controllerDebugInfo.UserFields.DebugDataList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				controllerDebugInfo.UserFields.DebugDataList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
