using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

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

	public override string DisplayGroup => "Host Control and Baseband";

	public HostNumberOfCompletedPacketsInfo(HostNumberOfCompletedPackets packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		HostNumberOfCompletedPackets hostNumberOfCompletedPackets = (HostNumberOfCompletedPackets)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Number_Of_Handles", "The number of Connection Handles and Host_Num_Of_Completed_Packets parameters pairs contained in this command. Range: 0-255", 8, FormatValue(hostNumberOfCompletedPackets.UserFields.NumberOfHandles, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < hostNumberOfCompletedPackets.UserFields.NHandlesList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Connection_Handle[" + i + "]", "Connection Handle. Range: 0x0000-0x0EFF.  Reserved for future use (0x0F00 - 0x0FFF)", 16, FormatValue(hostNumberOfCompletedPackets.UserFields.NHandlesList[i].ConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Host_Num_Of_Completed_Packets[" + i + "]", "The number of HCI Data Packets that have been completed for the associated Connection Handle since the previous time the event was returned. Range for N: 0x0000-0xFFFF", 16, FormatValue(hostNumberOfCompletedPackets.UserFields.NHandlesList[i].HostNumOfCompletedPackets, 16), "", "0000", "FFFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		HostNumberOfCompletedPackets hostNumberOfCompletedPackets = (HostNumberOfCompletedPackets)packet;
		int num = -1;
		if (index == ++num)
		{
			hostNumberOfCompletedPackets.UserFields.NumberOfHandles = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < hostNumberOfCompletedPackets.UserFields.NHandlesList.Count; i++)
		{
			if (index == ++num)
			{
				hostNumberOfCompletedPackets.UserFields.NHandlesList[i].ConnectionHandle = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				hostNumberOfCompletedPackets.UserFields.NHandlesList[i].HostNumOfCompletedPackets = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
