using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class ReadResetReasonEventInfo : PacketInfoBase
{
	public override string Name => "Read Reset Reason Event";

	public override string DisplayGroup => "Vendor Specific";

	public ReadResetReasonEventInfo(ReadResetReasonEvent packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		ReadResetReasonEvent readResetReasonEvent = (ReadResetReasonEvent)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Vendor_Event_Class", "HCI_VS_DEBUG_OPCODE", 8, FormatValue(readResetReasonEvent.UserFields.VendorEventClass, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("SubOpCode", "HCI_VS_DEBUG_READ_RESET_REASON_CMD", 8, FormatValue(readResetReasonEvent.UserFields.Subopcode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Reset_Reason", ReadResetReasonEvent.UserFieldsWrapper.ResetReasonInfo.ResetReasonToDescription(), 16, FormatValue(readResetReasonEvent.UserFields.ResetReason, 16), ReadResetReasonEvent.UserFieldsWrapper.ResetReasonInfo.ResetReasonToString(ReadResetReasonEvent.UserFieldsWrapper.ResetReasonInfo.ValueToResetReason(readResetReasonEvent.UserFields.ResetReason)), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Debug_info_1", "Exception Type", 32, FormatValue(readResetReasonEvent.UserFields.DebugInfo1, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Debug_info_2", "Exception PC", 32, FormatValue(readResetReasonEvent.UserFields.DebugInfo2, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		ReadResetReasonEvent readResetReasonEvent = (ReadResetReasonEvent)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field VendorEventClass");
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field Subopcode");
		}
		if (index == ++num)
		{
			readResetReasonEvent.UserFields.ResetReason = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			readResetReasonEvent.UserFields.DebugInfo1 = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			readResetReasonEvent.UserFields.DebugInfo2 = Convert.ToUInt32(value, 16);
		}
	}
}
