using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class FlowSpecificationInfo : PacketInfoBase
{
	public override string Name => "Flow Specification";

	public override string DisplayGroup => "Link Policy";

	public FlowSpecificationInfo(FlowSpecification packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		FlowSpecification flowSpecification = (FlowSpecification)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Connection_Handle", "Connection_Handle used to identify for which ACL connection the Flow is specified. Range: 0x0000-0x0EFF (0x0F00 - 0x0FFF Reserved for future use)", 16, FormatValue(flowSpecification.UserFields.ConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Flags", FlowSpecification.UserFieldsWrapper.FlagsInfo.FlagsToDescription(), 8, FormatValue(flowSpecification.UserFields.Flags, 8), FlowSpecification.UserFieldsWrapper.FlagsInfo.FlagsToString(FlowSpecification.UserFieldsWrapper.FlagsInfo.ValueToFlags(flowSpecification.UserFields.Flags)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Flow_direction", FlowSpecification.UserFieldsWrapper.FlowDirectionInfo.FlowDirectionToDescription(), 8, FormatValue(flowSpecification.UserFields.FlowDirection, 8), FlowSpecification.UserFieldsWrapper.FlowDirectionInfo.FlowDirectionToString(FlowSpecification.UserFieldsWrapper.FlowDirectionInfo.ValueToFlowDirection(flowSpecification.UserFields.FlowDirection)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Service_Type", FlowSpecification.UserFieldsWrapper.ServiceTypeInfo.ServiceTypeToDescription(), 8, FormatValue(flowSpecification.UserFields.ServiceType, 8), FlowSpecification.UserFieldsWrapper.ServiceTypeInfo.ServiceTypeToString(FlowSpecification.UserFieldsWrapper.ServiceTypeInfo.ValueToServiceType(flowSpecification.UserFields.ServiceType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Token_Rate", "Token Rate in octets per second", 32, FormatValue(flowSpecification.UserFields.TokenRate, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Token_Bucket_Size", "Token Bucket Size in octets", 32, FormatValue(flowSpecification.UserFields.TokenBucketSize, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Peak_Bandwidth", "Peak Bandwidth in octets per second", 32, FormatValue(flowSpecification.UserFields.PeakBandwidth, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Access_Latency", "Latency in microseconds", 32, FormatValue(flowSpecification.UserFields.AccessLatency, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		FlowSpecification flowSpecification = (FlowSpecification)packet;
		int num = -1;
		if (index == ++num)
		{
			flowSpecification.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			flowSpecification.UserFields.Flags = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			flowSpecification.UserFields.FlowDirection = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			flowSpecification.UserFields.ServiceType = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			flowSpecification.UserFields.TokenRate = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			flowSpecification.UserFields.TokenBucketSize = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			flowSpecification.UserFields.PeakBandwidth = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			flowSpecification.UserFields.AccessLatency = Convert.ToUInt32(value, 16);
		}
	}
}
