using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class ProdTestQhsInfo : PacketInfoBase
{
	public override string Name => "Prod Test Qhs";

	public override string DisplayGroup => "Vendor Specific";

	public ProdTestQhsInfo(ProdTestQhs packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		ProdTestQhs prodTestQhs = (ProdTestQhs)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("SubOpCode", ProdTestQhs.UserFieldsWrapper.SubopcodeInfo.SubopcodeToDescription(), 8, FormatValue(prodTestQhs.UserFields.Subopcode, 8), ProdTestQhs.UserFieldsWrapper.SubopcodeInfo.SubopcodeToString(ProdTestQhs.UserFieldsWrapper.SubopcodeInfo.ValueToSubopcode(prodTestQhs.UserFields.Subopcode)), "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Test_Mode", ProdTestQhs.UserFieldsWrapper.TestModeInfo.TestModeToDescription(), 8, FormatValue(prodTestQhs.UserFields.TestMode, 8), ProdTestQhs.UserFieldsWrapper.TestModeInfo.TestModeToString(ProdTestQhs.UserFieldsWrapper.TestModeInfo.ValueToTestMode(prodTestQhs.UserFields.TestMode)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Channel", "Channel number. N = (F - 2402) / 2; 0x00 = 2402MHz; 0x27 = 2480MHz", 8, FormatValue(prodTestQhs.UserFields.Channel, 8), CteFrequencyValueExpression.CteFrequencyValueToString(prodTestQhs.UserFields.Channel), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Payload_Length", "", 16, FormatValue(prodTestQhs.UserFields.PayloadLength, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Payload_Pattern", PayloadPatternInfo.PayloadPatternToDescription(), 8, FormatValue(prodTestQhs.UserFields.PayloadPattern, 8), PayloadPatternInfo.PayloadPatternToString(PayloadPatternInfo.ValueToPayloadPattern(prodTestQhs.UserFields.PayloadPattern)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("PHY_Rate", ProdTestQhs.UserFieldsWrapper.PhyRateInfo.PhyRateToDescription(), 8, FormatValue(prodTestQhs.UserFields.PhyRate, 8), ProdTestQhs.UserFieldsWrapper.PhyRateInfo.PhyRateToString(ProdTestQhs.UserFieldsWrapper.PhyRateInfo.ValueToPhyRate(prodTestQhs.UserFields.PhyRate)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Tx Power Index", ProdTestQhs.UserFieldsWrapper.TxPowerIndexInfo.TxPowerIndexToDescription(), 8, FormatValue(prodTestQhs.UserFields.TxPowerIndex, 8), ProdTestQhs.UserFieldsWrapper.TxPowerIndexInfo.TxPowerIndexToString(ProdTestQhs.UserFieldsWrapper.TxPowerIndexInfo.ValueToTxPowerIndex(prodTestQhs.UserFields.TxPowerIndex)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Max packets", "Max number of packets to transmit after Tx mode is initiated. 0 to transmit indefinitely", 16, FormatValue(prodTestQhs.UserFields.MaxPackets, 16), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		ProdTestQhs prodTestQhs = (ProdTestQhs)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field Subopcode");
		}
		if (index == ++num)
		{
			prodTestQhs.UserFields.TestMode = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			prodTestQhs.UserFields.Channel = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			prodTestQhs.UserFields.PayloadLength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			prodTestQhs.UserFields.PayloadPattern = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			prodTestQhs.UserFields.PhyRate = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			prodTestQhs.UserFields.TxPowerIndex = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			prodTestQhs.UserFields.MaxPackets = Convert.ToUInt32(value, 16);
		}
	}
}
