using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class DebugSimulateCxmMwsRxInfo : PacketInfoBase
{
	public override string Name => "Debug Simulate Cxm Mws Rx";

	public override string DisplayGroup => "Vendor Specific";

	public DebugSimulateCxmMwsRxInfo(DebugSimulateCxmMwsRx packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		DebugSimulateCxmMwsRx debugSimulateCxmMwsRx = (DebugSimulateCxmMwsRx)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Sub OpCode", "HCI_VS_DEBUG_CXM_MWS_RX_CMD", 8, FormatValue(debugSimulateCxmMwsRx.UserFields.SubOpcode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("MWS_Type", "MWS type defined in Table 3.2 Message Types (p. 116) from Bluetooth Core Specification Addendum 3 (MWS/WCI-1/WCI-2).\r\n\r\n" + DebugSimulateCxmMwsRx.UserFieldsWrapper.MwsTypeInfo.MwsTypeToDescription(), 8, FormatValue(debugSimulateCxmMwsRx.UserFields.MwsType, 8), DebugSimulateCxmMwsRx.UserFieldsWrapper.MwsTypeInfo.MwsTypeToString(DebugSimulateCxmMwsRx.UserFieldsWrapper.MwsTypeInfo.ValueToMwsType(debugSimulateCxmMwsRx.UserFields.MwsType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("MWS_Body_Length", "A length of MwsBody.", 8, FormatValue(debugSimulateCxmMwsRx.UserFields.MwsBodyLength, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("MWS_Body", "A body of up to 60 bytes including address and payload (This is the current maximum size of TYPE2 message without an hdlc-type frame, CRC-16 and escape.)", debugSimulateCxmMwsRx.UserFields.MwsBodyList.Count * 8, FormatValue(debugSimulateCxmMwsRx.UserFields.MwsBodyList, debugSimulateCxmMwsRx.UserFields.MwsBodyList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		DebugSimulateCxmMwsRx debugSimulateCxmMwsRx = (DebugSimulateCxmMwsRx)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubOpcode");
		}
		if (index == ++num)
		{
			debugSimulateCxmMwsRx.UserFields.MwsType = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			debugSimulateCxmMwsRx.UserFields.MwsBodyLength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, debugSimulateCxmMwsRx.UserFields.MwsBodyList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				debugSimulateCxmMwsRx.UserFields.MwsBodyList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
