using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class SetParametersInfo : PacketInfoBase
{
	public override string Name => "Set Parameters";

	public override string DisplayGroup => "Vendor Specific Legacy Atheros";

	public SetParametersInfo(SetParameters packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		SetParameters setParameters = (SetParameters)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Test Mode", Ar3002TestModeInfo.Ar3002TestModeToDescription(), 8, FormatValue(setParameters.UserFields.TestMode, 8), Ar3002TestModeInfo.Ar3002TestModeToString(Ar3002TestModeInfo.ValueToAr3002TestMode(setParameters.UserFields.TestMode)), "", "0B", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Packet Type", Ar3002PacketTypeInfo.Ar3002PacketTypeToDescription(), 8, FormatValue(setParameters.UserFields.PacketType, 8), Ar3002PacketTypeInfo.Ar3002PacketTypeToString(Ar3002PacketTypeInfo.ValueToAr3002PacketType(setParameters.UserFields.PacketType)), "", "0D", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Data Length", "", 16, FormatValue(setParameters.UserFields.DataLength, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Hop Mode", "0x00 = disable hop; 0x01-0xFF = enable hop", 8, FormatValue(setParameters.UserFields.HopMode, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("TX Frequency", "", 8, FormatValue(setParameters.UserFields.TxFrequency, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("TX Power", "", 8, FormatValue(setParameters.UserFields.TxPower, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("RX Frequency", "", 8, FormatValue(setParameters.UserFields.RxFrequency, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Bluetooth Device Address", "", 48, FormatValue(setParameters.UserFields.BluetoothDeviceAddress, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Skip RX Slot", "", 8, FormatValue(setParameters.UserFields.SkipRxSlot, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		SetParameters setParameters = (SetParameters)packet;
		int num = -1;
		if (index == ++num)
		{
			setParameters.UserFields.TestMode = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			setParameters.UserFields.PacketType = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			setParameters.UserFields.DataLength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			setParameters.UserFields.HopMode = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			setParameters.UserFields.TxFrequency = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			setParameters.UserFields.TxPower = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			setParameters.UserFields.RxFrequency = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			setParameters.UserFields.BluetoothDeviceAddress = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			setParameters.UserFields.SkipRxSlot = Convert.ToUInt32(value, 16);
		}
	}
}
