using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LogicalLinkCompleteInfo : PacketInfoBase
{
	public override string Name => "Logical Link Complete";

	public override string DisplayGroup => "Link Control";

	public LogicalLinkCompleteInfo(LogicalLinkComplete packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LogicalLinkComplete logicalLinkComplete = (LogicalLinkComplete)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(logicalLinkComplete.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(logicalLinkComplete.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Logical_Link_Handle", "", 16, FormatValue(logicalLinkComplete.UserFields.LogicalLinkHandle, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Physical_Link_Handle", "Physical_Link identifying the physical link over which the logical link has been created.", 8, FormatValue(logicalLinkComplete.UserFields.PhysicalLinkHandle, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Tx_Flow_Spec_ID", "Flow Spec ID identifying the logical link creation that completed. This matches the ID field of the TX_Flow_Spec", 8, FormatValue(logicalLinkComplete.UserFields.TxFlowSpecId, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LogicalLinkComplete logicalLinkComplete = (LogicalLinkComplete)packet;
		int num = -1;
		if (index == ++num)
		{
			logicalLinkComplete.UserFields.Status = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			logicalLinkComplete.UserFields.LogicalLinkHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			logicalLinkComplete.UserFields.PhysicalLinkHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			logicalLinkComplete.UserFields.TxFlowSpecId = Convert.ToUInt32(value, 16);
		}
	}
}
