using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class CreateLogicalLinkInfo : PacketInfoBase
{
	public override string Name => "Create Logical Link";

	public override string DisplayGroup => "Link Control";

	public CreateLogicalLinkInfo(CreateLogicalLink packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		CreateLogicalLink createLogicalLink = (CreateLogicalLink)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Physical_Link_Handle", "Physical Link Handle identifying the physical link to be created.", 8, FormatValue(createLogicalLink.UserFields.PhysicalLinkHandle, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Tx_Flow_Spec", "Extended Flow Specification value defining transmitted traffic. See BT Specification document, EXTENDED FLOW SPECIFICATION OPTION", createLogicalLink.UserFields.TxFlowSpecList.Count * 8, FormatValue(createLogicalLink.UserFields.TxFlowSpecList, createLogicalLink.UserFields.TxFlowSpecList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Rx_Flow_Spec", "Extended Flow Specification value defining received traffic. See BT Specification document, EXTENDED FLOW SPECIFICATION OPTION ", createLogicalLink.UserFields.RxFlowSpecList.Count * 8, FormatValue(createLogicalLink.UserFields.RxFlowSpecList, createLogicalLink.UserFields.RxFlowSpecList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		CreateLogicalLink createLogicalLink = (CreateLogicalLink)packet;
		int num = -1;
		if (index == ++num)
		{
			createLogicalLink.UserFields.PhysicalLinkHandle = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, createLogicalLink.UserFields.TxFlowSpecList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				createLogicalLink.UserFields.TxFlowSpecList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
		if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, createLogicalLink.UserFields.RxFlowSpecList.Count);
			int num3 = 0;
			while (value.Length > 0)
			{
				string value3 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				createLogicalLink.UserFields.RxFlowSpecList[num3] = Convert.ToUInt32(value3, 16);
				num3++;
			}
		}
	}
}
