using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class AcceptPhysicalLinkInfo : PacketInfoBase
{
	public override string Name => "Accept Physical Link";

	public override string DisplayGroup => "Link Control";

	public AcceptPhysicalLinkInfo(AcceptPhysicalLink packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		AcceptPhysicalLink acceptPhysicalLink = (AcceptPhysicalLink)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Physical_Link_Handle", "Physical Link Handle identifying the physical link to be created.", 8, FormatValue(acceptPhysicalLink.UserFields.PhysicalLinkHandle, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Dedicated_AMP_Key_Length", "See Assigned Numbers. 0 and 33-255 are Reserved", 8, FormatValue(acceptPhysicalLink.UserFields.DedicatedAmpKeyLength, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Dedicated_AMP_Key_Type", AcceptPhysicalLink.UserFieldsWrapper.DedicatedAmpKeyTypeInfo.DedicatedAmpKeyTypeToDescription(), 8, FormatValue(acceptPhysicalLink.UserFields.DedicatedAmpKeyType, 8), AcceptPhysicalLink.UserFieldsWrapper.DedicatedAmpKeyTypeInfo.DedicatedAmpKeyTypeToString(AcceptPhysicalLink.UserFieldsWrapper.DedicatedAmpKeyTypeInfo.ValueToDedicatedAmpKeyType(acceptPhysicalLink.UserFields.DedicatedAmpKeyType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Dedicated_AMP_Key", "Dedicated AMP Key for the associated AMP. The Dedicated AMP Key is a multi-octet integer.", acceptPhysicalLink.UserFields.DedicatedAmpKeyList.Count * 8, FormatValue(acceptPhysicalLink.UserFields.DedicatedAmpKeyList, acceptPhysicalLink.UserFields.DedicatedAmpKeyList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		AcceptPhysicalLink acceptPhysicalLink = (AcceptPhysicalLink)packet;
		int num = -1;
		if (index == ++num)
		{
			acceptPhysicalLink.UserFields.PhysicalLinkHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			acceptPhysicalLink.UserFields.DedicatedAmpKeyLength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			acceptPhysicalLink.UserFields.DedicatedAmpKeyType = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, acceptPhysicalLink.UserFields.DedicatedAmpKeyList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				acceptPhysicalLink.UserFields.DedicatedAmpKeyList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
