using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class ProdTestSlaveInfo : PacketInfoBase
{
	public override string Name => "Prod Test Slave";

	public override string DisplayGroup => "Vendor Specific";

	public ProdTestSlaveInfo(ProdTestSlave packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		ProdTestSlave prodTestSlave = (ProdTestSlave)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("SubOpCode", "PROD_TEST_SLAVE", 8, FormatValue(prodTestSlave.UserFields.Subopcode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Hop_Channel_1", "1 of 5 hopping channels used if limited hopping enabled in offset 20. Channel Numer: (0x00 = low channel 0, 0x27 = mid channel 39, 0x4E = high channel 78)", 8, FormatValue(prodTestSlave.UserFields.HopChannel1, 8), "", "", "4E", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Hop_Channel_2", "1 of 5 hopping channels used if limited hopping enabled in offset 20. Channel Numer: (0x00 = low channel 0, 0x27 = mid channel 39, 0x4E = high channel 78)", 8, FormatValue(prodTestSlave.UserFields.HopChannel2, 8), "", "", "4E", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Hop_Channel_3", "1 of 5 hopping channels used if limited hopping enabled in offset 20. Channel Numer: (0x00 = low channel 0, 0x27 = mid channel 39, 0x4E = high channel 78)", 8, FormatValue(prodTestSlave.UserFields.HopChannel3, 8), "", "", "4E", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Hop_Channel_4", "1 of 5 hopping channels used if limited hopping enabled in offset 20. Channel Numer: (0x00 = low channel 0, 0x27 = mid channel 39, 0x4E = high channel 78)", 8, FormatValue(prodTestSlave.UserFields.HopChannel4, 8), "", "", "4E", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Hop_Channel_5", "1 of 5 hopping channels used if limited hopping enabled in offset 20. Channel Numer: (0x00 = low channel 0, 0x27 = mid channel 39, 0x4E = high channel 78)", 8, FormatValue(prodTestSlave.UserFields.HopChannel5, 8), "", "", "4E", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("TX_Pattern_Payload", "Transmitted pattern payload, independent of the master pattern.\r\n\r\n" + ProdTestSlave.UserFieldsWrapper.TxPatternPayloadInfo.TxPatternPayloadToDescription(), 8, FormatValue(prodTestSlave.UserFields.TxPatternPayload, 8), ProdTestSlave.UserFieldsWrapper.TxPatternPayloadInfo.TxPatternPayloadToString(ProdTestSlave.UserFieldsWrapper.TxPatternPayloadInfo.ValueToTxPatternPayload(prodTestSlave.UserFields.TxPatternPayload)), "", "04", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Packet_Type", ProdTestSlave.UserFieldsWrapper.PacketTypeInfo.PacketTypeToDescription(), 8, FormatValue(prodTestSlave.UserFields.PacketType, 8), ProdTestSlave.UserFieldsWrapper.PacketTypeInfo.PacketTypeToString(ProdTestSlave.UserFieldsWrapper.PacketTypeInfo.ValueToPacketType(prodTestSlave.UserFields.PacketType)), "", "3D", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Data_Whitening", "0 = whitening off; 1 = whitening on", 8, FormatValue(prodTestSlave.UserFields.DataWhitening, 8), "", "", "01", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Transmit_Output_Power", "0x00 = lowest power; 0x07 = highest power for BTS4020/21/BD; 0x09 = highest power for BTS4025, QSC/QTR, WCN2243, WCN3660 and QCA6174 (Rome)", 8, FormatValue(prodTestSlave.UserFields.TransmitOutputPower, 8), "", "", "09", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Receiver_Gain", "00 = low; 01 = high", 8, FormatValue(prodTestSlave.UserFields.ReceiverGain, 8), "", "", "01", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Bluetooth_Target_Device_Address", "Master_Bluetooth_device_address", 48, FormatValue(prodTestSlave.UserFields.BluetoothTargetDeviceAddress, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Hopping_Functionality", "0 = device hops over all five hop channels; 1 = device starts at specified hop channel (0), then hops over the full range of channels", 8, FormatValue(prodTestSlave.UserFields.HoppingFunctionality, 8), "", "", "01", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Payload_Length", "", 16, FormatValue(prodTestSlave.UserFields.PayloadLength, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Logical_Transport_Address", "", 8, FormatValue(prodTestSlave.UserFields.LogicalTransportAddress, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		ProdTestSlave prodTestSlave = (ProdTestSlave)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field Subopcode");
		}
		if (index == ++num)
		{
			prodTestSlave.UserFields.HopChannel1 = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			prodTestSlave.UserFields.HopChannel2 = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			prodTestSlave.UserFields.HopChannel3 = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			prodTestSlave.UserFields.HopChannel4 = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			prodTestSlave.UserFields.HopChannel5 = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			prodTestSlave.UserFields.TxPatternPayload = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			prodTestSlave.UserFields.PacketType = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			prodTestSlave.UserFields.DataWhitening = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			prodTestSlave.UserFields.TransmitOutputPower = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			prodTestSlave.UserFields.ReceiverGain = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			prodTestSlave.UserFields.BluetoothTargetDeviceAddress = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			prodTestSlave.UserFields.HoppingFunctionality = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			prodTestSlave.UserFields.PayloadLength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			prodTestSlave.UserFields.LogicalTransportAddress = Convert.ToUInt32(value, 16);
		}
	}
}
