using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class NumberOfCompletedPacketsEventInfo : PacketInfoBase
{
	public override string Name => "Number Of Completed Packets Event";

	public override string DisplayGroup => "Link Policy";

	public NumberOfCompletedPacketsEventInfo(NumberOfCompletedPacketsEvent packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		NumberOfCompletedPacketsEvent numberOfCompletedPacketsEvent = (NumberOfCompletedPacketsEvent)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("NUM_OF_HANDLES", "The number of Connection_Handles and Num_HCI_Data_Packets parameters pairs contained in this event.", 8, FormatValue(numberOfCompletedPacketsEvent.UserFields.NumOfHandles, 8), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("CONNECTION_HANDLE", "Connection_Handle", 16, FormatValue(numberOfCompletedPacketsEvent.UserFields.ConnectionHandle, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("HC_NUM_OF_COMPLETED_PACKETS", "The number of HCI Data Packets that have been completed (transmitted or flushed) for the associated Connection_Handle since the previous time the event was returned.", 16, FormatValue(numberOfCompletedPacketsEvent.UserFields.HcNumOfCompletedPackets, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

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