using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class ProdTestRxContinuousInfo : PacketInfoBase
{
	public override string Name => "Prod Test Rx Continuous";

	public override string DisplayGroup => "Vendor Specific";

	public ProdTestRxContinuousInfo(ProdTestRxContinuous packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		ProdTestRxContinuous prodTestRxContinuous = (ProdTestRxContinuous)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Sub opcode", "", 8, FormatValue(prodTestRxContinuous.UserFields.SubOpcode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Tech Type", ProdTestRxContinuous.UserFieldsWrapper.TechTypeInfo.TechTypeToDescription(), 8, FormatValue(prodTestRxContinuous.UserFields.TechType, 8), ProdTestRxContinuous.UserFieldsWrapper.TechTypeInfo.TechTypeToString(ProdTestRxContinuous.UserFieldsWrapper.TechTypeInfo.ValueToTechType(prodTestRxContinuous.UserFields.TechType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Channel", "Channel number. Range: 0-78 for BR/EDR and 0-39 for BLE.", 8, FormatValue(prodTestRxContinuous.UserFields.Channel, 8), "", "00", "4E", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.DecimalInteger));
		fieldInfoList.Add(new PacketFieldInfo("SW Gain", ProdTestRxContinuous.UserFieldsWrapper.SwGainInfo.SwGainToDescription(), 8, FormatValue(prodTestRxContinuous.UserFields.SwGain, 8), ProdTestRxContinuous.UserFieldsWrapper.SwGainInfo.SwGainToString(ProdTestRxContinuous.UserFieldsWrapper.SwGainInfo.ValueToSwGain(prodTestRxContinuous.UserFields.SwGain)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < prodTestRxContinuous.UserFields.LePhyList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("LE_PHY[" + i + "]", ProdTestRxContinuous.UserFieldsWrapper.LePhyInfo.LePhyToDescription(), 8, FormatValue(prodTestRxContinuous.UserFields.LePhyList[i], 8), ProdTestRxContinuous.UserFieldsWrapper.LePhyInfo.LePhyToString(ProdTestRxContinuous.UserFieldsWrapper.LePhyInfo.ValueToLePhy(prodTestRxContinuous.UserFields.LePhyList[i])), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		ProdTestRxContinuous prodTestRxContinuous = (ProdTestRxContinuous)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubOpcode");
		}
		if (index == ++num)
		{
			prodTestRxContinuous.UserFields.TechType = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			prodTestRxContinuous.UserFields.Channel = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			prodTestRxContinuous.UserFields.SwGain = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < prodTestRxContinuous.UserFields.LePhyList.Count; i++)
		{
			if (index == ++num)
			{
				prodTestRxContinuous.UserFields.LePhyList[i] = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
