using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class QosSetupInfo : PacketInfoBase
{
	public override string Name => "Qos Setup";

	public override string DisplayGroup => "Link Policy";

	public QosSetupInfo(QosSetup packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		QosSetup qosSetup = (QosSetup)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Connection_Handle", "Connection_Handle to be used to identify which connection for the QoS Setup. Range: 0x0000-0x0EFF (0x0F00 - 0x0FFF Reserved for future use)", 16, FormatValue(qosSetup.UserFields.ConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Flags", QosSetup.UserFieldsWrapper.FlagsInfo.FlagsToDescription(), 8, FormatValue(qosSetup.UserFields.Flags, 8), QosSetup.UserFieldsWrapper.FlagsInfo.FlagsToString(QosSetup.UserFieldsWrapper.FlagsInfo.ValueToFlags(qosSetup.UserFields.Flags)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Service_Type", QosSetup.UserFieldsWrapper.ServiceTypeInfo.ServiceTypeToDescription(), 8, FormatValue(qosSetup.UserFields.ServiceType, 8), QosSetup.UserFieldsWrapper.ServiceTypeInfo.ServiceTypeToString(QosSetup.UserFieldsWrapper.ServiceTypeInfo.ValueToServiceType(qosSetup.UserFields.ServiceType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Token_Rate", "Token Rate in octets per second", 32, FormatValue(qosSetup.UserFields.TokenRate, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Peak_Bandwidth", "Peak Bandwidth in octets per second", 32, FormatValue(qosSetup.UserFields.PeakBandwidth, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Latency", "Latency in microseconds", 32, FormatValue(qosSetup.UserFields.Latency, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Delay_Variation", "Delay Variation in microseconds", 32, FormatValue(qosSetup.UserFields.DelayVariation, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		QosSetup qosSetup = (QosSetup)packet;
		int num = -1;
		if (index == ++num)
		{
			qosSetup.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			qosSetup.UserFields.Flags = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			qosSetup.UserFields.ServiceType = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			qosSetup.UserFields.TokenRate = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			qosSetup.UserFields.PeakBandwidth = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			qosSetup.UserFields.Latency = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			qosSetup.UserFields.DelayVariation = Convert.ToUInt32(value, 16);
		}
	}
}
