using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class ConnectionPacketTypeChangeEventInfo : PacketInfoBase
{
	public override string Name => "Connection Packet Type Change Event";

	public override string DisplayGroup => "Link Control";

	public ConnectionPacketTypeChangeEventInfo(ConnectionPacketTypeChangeEvent packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		ConnectionPacketTypeChangeEvent connectionPacketTypeChangeEvent = (ConnectionPacketTypeChangeEvent)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(connectionPacketTypeChangeEvent.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(connectionPacketTypeChangeEvent.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Connection Handle", "Connection_Handle. Range: 0x0000-0x0EFF (0x0F00 - 0x0FFF Reserved for future use)", 16, FormatValue(connectionPacketTypeChangeEvent.UserFields.ConnectionHandle, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		if (connectionPacketTypeChangeEvent.UserFields.PacketType >= 0 && connectionPacketTypeChangeEvent.UserFields.PacketType <= 31)
		{
			fieldInfoList.Add(new PacketFieldInfo("Packet Type", AclPacketTypeInfo.AclPacketTypeToDescription(), 16, FormatValue(connectionPacketTypeChangeEvent.UserFields.PacketType, 16), AclPacketTypeInfo.AclPacketTypeToString(AclPacketTypeInfo.ValueToAclPacketType(connectionPacketTypeChangeEvent.UserFields.PacketType)), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
		else if (connectionPacketTypeChangeEvent.UserFields.PacketType >= 32 && connectionPacketTypeChangeEvent.UserFields.PacketType <= 224)
		{
			fieldInfoList.Add(new PacketFieldInfo("Packet Type", SynchronousPacketTypeInfo.SynchronousPacketTypeToDescription(), 16, FormatValue(connectionPacketTypeChangeEvent.UserFields.PacketType, 16), SynchronousPacketTypeInfo.SynchronousPacketTypeToString(SynchronousPacketTypeInfo.ValueToSynchronousPacketType(connectionPacketTypeChangeEvent.UserFields.PacketType)), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
		else if (connectionPacketTypeChangeEvent.UserFields.PacketType >= 256 && connectionPacketTypeChangeEvent.UserFields.PacketType <= 65535)
		{
			fieldInfoList.Add(new PacketFieldInfo("Packet Type", AclPacketTypeInfo.AclPacketTypeToDescription(), 16, FormatValue(connectionPacketTypeChangeEvent.UserFields.PacketType, 16), AclPacketTypeInfo.AclPacketTypeToString(AclPacketTypeInfo.ValueToAclPacketType(connectionPacketTypeChangeEvent.UserFields.PacketType)), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
		else
		{
			fieldInfoList.Add(new PacketFieldInfo("Packet Type", "", 16, FormatValue(connectionPacketTypeChangeEvent.UserFields.PacketType, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

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