using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class DisconnectInfo : PacketInfoBase
{
	public override string Name => "Disconnect";

	public override string DisplayGroup => "Link Control";

	public DisconnectInfo(Disconnect packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		Disconnect disconnect = (Disconnect)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Connection Handle", "Connection handle for the connection being disconnected.", 16, FormatValue(disconnect.UserFields.ConnectionHandle, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Reason", Disconnect.UserFieldsWrapper.ReasonInfo.ReasonToDescription(), 8, FormatValue(disconnect.UserFields.Reason, 8), Disconnect.UserFieldsWrapper.ReasonInfo.ReasonToString(Disconnect.UserFieldsWrapper.ReasonInfo.ValueToReason(disconnect.UserFields.Reason)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

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