using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeTransmitterTestV3Info : PacketInfoBase
{
	public override string Name => "Le Transmitter Test V3";

	public override string DisplayGroup => "LE Controller";

	public LeTransmitterTestV3Info(LeTransmitterTestV3 packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeTransmitterTestV3 leTransmitterTestV = (LeTransmitterTestV3)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("TX_Channel", "Channel number. N = (F - 2402) / 2; 0x00 = 2402MHz; 0x27 = 2480MHz", 8, FormatValue(leTransmitterTestV.UserFields.TxChannel, 8), CteFrequencyValueExpression.CteFrequencyValueToString(leTransmitterTestV.UserFields.TxChannel), "", "27", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Length_of_Test Data", "Length in bytes of payload data in each packet", 8, FormatValue(leTransmitterTestV.UserFields.LengthOfTestData, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Packet_Payload", LeTransmitterTestV3.UserFieldsWrapper.PacketPayloadInfo.PacketPayloadToDescription(), 8, FormatValue(leTransmitterTestV.UserFields.PacketPayload, 8), LeTransmitterTestV3.UserFieldsWrapper.PacketPayloadInfo.PacketPayloadToString(LeTransmitterTestV3.UserFieldsWrapper.PacketPayloadInfo.ValueToPacketPayload(leTransmitterTestV.UserFields.PacketPayload)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("PHY", LeTransmitterTestV3.UserFieldsWrapper.PhyInfo.PhyToDescription(), 8, FormatValue(leTransmitterTestV.UserFields.Phy, 8), LeTransmitterTestV3.UserFieldsWrapper.PhyInfo.PhyToString(LeTransmitterTestV3.UserFieldsWrapper.PhyInfo.ValueToPhy(leTransmitterTestV.UserFields.Phy)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("CTE_Length", LeTransmitterTestV3.UserFieldsWrapper.CteLengthInfo.CteLengthToDescription(), 8, FormatValue(leTransmitterTestV.UserFields.CteLength, 8), LeTransmitterTestV3.UserFieldsWrapper.CteLengthInfo.CteLengthToString(LeTransmitterTestV3.UserFieldsWrapper.CteLengthInfo.ValueToCteLength(leTransmitterTestV.UserFields.CteLength)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Supplemental_Slot_Type", SlotTypeInfo.SlotTypeToDescription(), 8, FormatValue(leTransmitterTestV.UserFields.SupplementalSlotType, 8), SlotTypeInfo.SlotTypeToString(SlotTypeInfo.ValueToSlotType(leTransmitterTestV.UserFields.SupplementalSlotType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Length_Of_Switching_Pattern", LeTransmitterTestV3.UserFieldsWrapper.LengthOfSwitchingPatternInfo.LengthOfSwitchingPatternToDescription(), 8, FormatValue(leTransmitterTestV.UserFields.LengthOfSwitchingPattern, 8), LeTransmitterTestV3.UserFieldsWrapper.LengthOfSwitchingPatternInfo.LengthOfSwitchingPatternToString(LeTransmitterTestV3.UserFieldsWrapper.LengthOfSwitchingPatternInfo.ValueToLengthOfSwitchingPattern(leTransmitterTestV.UserFields.LengthOfSwitchingPattern)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < leTransmitterTestV.UserFields.AntennaIdsSetList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Antenna_IDs[" + i + "]", "", 8, FormatValue(leTransmitterTestV.UserFields.AntennaIdsSetList[i].AntennaIds, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeTransmitterTestV3 leTransmitterTestV = (LeTransmitterTestV3)packet;
		int num = -1;
		if (index == ++num)
		{
			leTransmitterTestV.UserFields.TxChannel = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leTransmitterTestV.UserFields.LengthOfTestData = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leTransmitterTestV.UserFields.PacketPayload = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leTransmitterTestV.UserFields.Phy = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leTransmitterTestV.UserFields.CteLength = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leTransmitterTestV.UserFields.SupplementalSlotType = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leTransmitterTestV.UserFields.LengthOfSwitchingPattern = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < leTransmitterTestV.UserFields.AntennaIdsSetList.Count; i++)
		{
			if (index == ++num)
			{
				leTransmitterTestV.UserFields.AntennaIdsSetList[i].AntennaIds = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
