using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class ProdTestListModeTxInfo : PacketInfoBase
{
	public override string Name => "Prod Test List Mode Tx";

	public override string DisplayGroup => "Vendor Specific";

	public ProdTestListModeTxInfo(ProdTestListModeTx packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		ProdTestListModeTx prodTestListModeTx = (ProdTestListModeTx)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Command", "", 8, FormatValue(prodTestListModeTx.UserFields.Command, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("PROD_TEST_List_Mode_TX", "PROD_TEST_List_Mode_TX\r\n\r\n" + ProdTestListModeTx.UserFieldsWrapper.ProdTestListModeTxInfo.ProdTestListModeTxToDescription(), 8, FormatValue(prodTestListModeTx.UserFields.ProdTestListModeTx, 8), ProdTestListModeTx.UserFieldsWrapper.ProdTestListModeTxInfo.ProdTestListModeTxToString(ProdTestListModeTx.UserFieldsWrapper.ProdTestListModeTxInfo.ValueToProdTestListModeTx(prodTestListModeTx.UserFields.ProdTestListModeTx)), "", "0B", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Channel", "Tx Channel", 8, FormatValue(prodTestListModeTx.UserFields.Channel, 8), "", "0", "4E", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Bluetooth Target Device Address", "Master Bluetooth device address", 48, FormatValue(prodTestListModeTx.UserFields.BluetoothTargetDeviceAddress, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Logical Transport Address", "", 8, FormatValue(prodTestListModeTx.UserFields.LogicalTransportAddress, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Transmit Output Power", "0x00 = lowest power; 0x09 = highest power", 8, FormatValue(prodTestListModeTx.UserFields.TransmitOutputPower, 8), "", "00", "09", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Number of packets", "Number of packets in sequence of each type", 16, FormatValue(prodTestListModeTx.UserFields.NumberOfPackets, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("NULL before sequence", "0x00 = No NULL packet at start of sequence ; 0x01 = NULL packet at start of each sequence", 8, FormatValue(prodTestListModeTx.UserFields.NullBeforeSequence, 8), "", "00", "01", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		ProdTestListModeTx prodTestListModeTx = (ProdTestListModeTx)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field Command");
		}
		if (index == ++num)
		{
			prodTestListModeTx.UserFields.ProdTestListModeTx = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			prodTestListModeTx.UserFields.Channel = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			prodTestListModeTx.UserFields.BluetoothTargetDeviceAddress = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			prodTestListModeTx.UserFields.LogicalTransportAddress = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			prodTestListModeTx.UserFields.TransmitOutputPower = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			prodTestListModeTx.UserFields.NumberOfPackets = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			prodTestListModeTx.UserFields.NullBeforeSequence = Convert.ToUInt32(value, 16);
		}
	}
}
