using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class CommandCompleteForReadDataBlockSizeInfo : PacketInfoBase
{
	public override string Name => "Command Complete For Read Data Block Size";

	public override string DisplayGroup => "Information Parameters";

	public CommandCompleteForReadDataBlockSizeInfo(CommandCompleteForReadDataBlockSize packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		CommandCompleteForReadDataBlockSize commandCompleteForReadDataBlockSize = (CommandCompleteForReadDataBlockSize)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Num HCI Command Packets", "", 8, FormatValue(commandCompleteForReadDataBlockSize.UserFields.NumHciCommandPackets, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Command OpCode", CommandOpcodeInfo.CommandOpcodeToDescription(), 16, FormatValue(commandCompleteForReadDataBlockSize.UserFields.CommandOpcode, 16), CommandOpcodeInfo.CommandOpcodeToString(CommandOpcodeInfo.ValueToCommandOpcode(commandCompleteForReadDataBlockSize.UserFields.CommandOpcode)), "", "", settable: false, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(commandCompleteForReadDataBlockSize.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(commandCompleteForReadDataBlockSize.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Max_ACL_Data_Packet_Length", "Maximum length (in octets) of the data portion of an HCI ACL Data Packet that the Controller is able to accept for transmission. For AMP Controllers this always equals to Max_PDU_Size.", 16, FormatValue(commandCompleteForReadDataBlockSize.UserFields.MaxAclDataPacketLength, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Data_Block_Length", "Maximum length (in octets) of the data portion of each HCI ACL Data Packet that the Controller is able to hold in each of its data block buffers.", 16, FormatValue(commandCompleteForReadDataBlockSize.UserFields.DataBlockLength, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Total_Num_Data_Blocks", "Total number of data block buffers available in the Controller for the storage of data packets scheduled for transmission.", 16, FormatValue(commandCompleteForReadDataBlockSize.UserFields.TotalNumDataBlocks, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		CommandCompleteForReadDataBlockSize commandCompleteForReadDataBlockSize = (CommandCompleteForReadDataBlockSize)packet;
		int num = -1;
		if (index == ++num)
		{
			commandCompleteForReadDataBlockSize.UserFields.NumHciCommandPackets = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field CommandOpcode");
		}
		if (index == ++num)
		{
			commandCompleteForReadDataBlockSize.UserFields.Status = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			commandCompleteForReadDataBlockSize.UserFields.MaxAclDataPacketLength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			commandCompleteForReadDataBlockSize.UserFields.DataBlockLength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			commandCompleteForReadDataBlockSize.UserFields.TotalNumDataBlocks = Convert.ToUInt32(value, 16);
		}
	}
}
