using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

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

	public override string DisplayGroup => "Link Policy";

	public QosSetupCompleteInfo(QosSetupComplete packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

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

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