using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class ProdTestListModeRxInfo : PacketInfoBase
{
	public override string Name => "Prod Test List Mode Rx";

	public override string DisplayGroup => "Vendor Specific";

	public ProdTestListModeRxInfo(ProdTestListModeRx packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		ProdTestListModeRx prodTestListModeRx = (ProdTestListModeRx)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Command", "", 8, FormatValue(prodTestListModeRx.UserFields.Command, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Number Of sequences in list", "The number of sequence fields to follow (n).", 8, FormatValue(prodTestListModeRx.UserFields.NumberOfSequencesInList, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Channel", "Rx Channel", 8, FormatValue(prodTestListModeRx.UserFields.Channel, 8), "", "0", "4E", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Bluetooth Target Device Address", "Master Bluetooth device address", 48, FormatValue(prodTestListModeRx.UserFields.BluetoothTargetDeviceAddress, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Logical Transport Address", "", 8, FormatValue(prodTestListModeRx.UserFields.LogicalTransportAddress, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Number of rotations", "Number of rotations for entire sequence", 16, FormatValue(prodTestListModeRx.UserFields.NumberOfRotations, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < prodTestListModeRx.UserFields.ParameterList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Packet Type[" + i + "]", "Bluetooth packet type\r\n\r\n" + ListModeRxPacketTypeInfo.ListModeRxPacketTypeToDescription(), 8, FormatValue(prodTestListModeRx.UserFields.ParameterList[i].PacketType, 8), ListModeRxPacketTypeInfo.ListModeRxPacketTypeToString(ListModeRxPacketTypeInfo.ValueToListModeRxPacketType(prodTestListModeRx.UserFields.ParameterList[i].PacketType)), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Payload Type[" + i + "]", "Bluetooth payload type\r\n\r\n" + ListModeRxPayloadTypeInfo.ListModeRxPayloadTypeToDescription(), 8, FormatValue(prodTestListModeRx.UserFields.ParameterList[i].PayloadType, 8), ListModeRxPayloadTypeInfo.ListModeRxPayloadTypeToString(ListModeRxPayloadTypeInfo.ValueToListModeRxPayloadType(prodTestListModeRx.UserFields.ParameterList[i].PayloadType)), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Payload Length[" + i + "]", "Payload length", 16, FormatValue(prodTestListModeRx.UserFields.ParameterList[i].PayloadLength, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Number of packets[" + i + "]", "Number of packets", 16, FormatValue(prodTestListModeRx.UserFields.ParameterList[i].NumberOfPackets, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		ProdTestListModeRx prodTestListModeRx = (ProdTestListModeRx)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field Command");
		}
		if (index == ++num)
		{
			prodTestListModeRx.UserFields.NumberOfSequencesInList = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			prodTestListModeRx.UserFields.Channel = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			prodTestListModeRx.UserFields.BluetoothTargetDeviceAddress = Convert.ToUInt64(value, 16);
			return;
		}
		if (index == ++num)
		{
			prodTestListModeRx.UserFields.LogicalTransportAddress = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			prodTestListModeRx.UserFields.NumberOfRotations = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < prodTestListModeRx.UserFields.ParameterList.Count; i++)
		{
			if (index == ++num)
			{
				prodTestListModeRx.UserFields.ParameterList[i].PacketType = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				prodTestListModeRx.UserFields.ParameterList[i].PayloadType = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				prodTestListModeRx.UserFields.ParameterList[i].PayloadLength = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				prodTestListModeRx.UserFields.ParameterList[i].NumberOfPackets = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
