using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LtDleTestInfo : PacketInfoBase
{
	public override string Name => "Lt Dle Test";

	public override string DisplayGroup => "Vendor Specific";

	public LtDleTestInfo(LtDleTest packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LtDleTest ltDleTest = (LtDleTest)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Sub OpCode", "Set DLE test parameters", 8, FormatValue(ltDleTest.UserFields.SubOpcode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Override", LtDleTest.UserFieldsWrapper.OverrideInfo.OverrideToDescription(), 8, FormatValue(ltDleTest.UserFields.Override, 8), LtDleTest.UserFieldsWrapper.OverrideInfo.OverrideToString(LtDleTest.UserFieldsWrapper.OverrideInfo.ValueToOverride(ltDleTest.UserFields.Override)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Max_Tx_Octets", "", 16, FormatValue(ltDleTest.UserFields.MaxTxOctets, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Max_Rx_Octets", "", 16, FormatValue(ltDleTest.UserFields.MaxRxOctets, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Max_Tx_Time", "", 16, FormatValue(ltDleTest.UserFields.MaxTxTime, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Max_Rx_Time", "", 16, FormatValue(ltDleTest.UserFields.MaxRxTime, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LtDleTest ltDleTest = (LtDleTest)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubOpcode");
		}
		if (index == ++num)
		{
			ltDleTest.UserFields.Override = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			ltDleTest.UserFields.MaxTxOctets = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			ltDleTest.UserFields.MaxRxOctets = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			ltDleTest.UserFields.MaxTxTime = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			ltDleTest.UserFields.MaxRxTime = Convert.ToUInt32(value, 16);
		}
	}
}
