using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

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

	public override string DisplayGroup => "Link Control";

	public DisconnectionLogicalLinkCompleteInfo(DisconnectionLogicalLinkComplete packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		DisconnectionLogicalLinkComplete disconnectionLogicalLinkComplete = (DisconnectionLogicalLinkComplete)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(disconnectionLogicalLinkComplete.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(disconnectionLogicalLinkComplete.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Logical_Link_Handle", DisconnectionLogicalLinkComplete.UserFieldsWrapper.LogicalLinkHandleInfo.LogicalLinkHandleToDescription(), 16, FormatValue(disconnectionLogicalLinkComplete.UserFields.LogicalLinkHandle, 16), DisconnectionLogicalLinkComplete.UserFieldsWrapper.LogicalLinkHandleInfo.LogicalLinkHandleToString(DisconnectionLogicalLinkComplete.UserFieldsWrapper.LogicalLinkHandleInfo.ValueToLogicalLinkHandle(disconnectionLogicalLinkComplete.UserFields.LogicalLinkHandle)), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Reason", "Reason for disconnection. See BT Specification document for Error Code and description.", 8, FormatValue(disconnectionLogicalLinkComplete.UserFields.Reason, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

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