using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class CommandCompleteForLeReadMaximumDataLengthInfo : PacketInfoBase
{
	public override string Name => "Command Complete For Le Read Maximum Data Length";

	public override string DisplayGroup => "LE Controller";

	public CommandCompleteForLeReadMaximumDataLengthInfo(CommandCompleteForLeReadMaximumDataLength packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		CommandCompleteForLeReadMaximumDataLength commandCompleteForLeReadMaximumDataLength = (CommandCompleteForLeReadMaximumDataLength)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Num HCI Command Packets", "", 8, FormatValue(commandCompleteForLeReadMaximumDataLength.UserFields.NumHciCommandPackets, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Command OpCode", CommandOpcodeInfo.CommandOpcodeToDescription(), 16, FormatValue(commandCompleteForLeReadMaximumDataLength.UserFields.CommandOpcode, 16), CommandOpcodeInfo.CommandOpcodeToString(CommandOpcodeInfo.ValueToCommandOpcode(commandCompleteForLeReadMaximumDataLength.UserFields.CommandOpcode)), "", "", settable: false, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(commandCompleteForLeReadMaximumDataLength.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(commandCompleteForLeReadMaximumDataLength.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Supported_Max_Tx_Octets", "Maximum number of payload octets that the local Controller supports for transmission of a single Link Layer Data Channel PDU. Range 0x001B-0x00FB (0x0000 - 0x001A and 0x00FC - 0xFFFF Reserved for future use)", 16, FormatValue(commandCompleteForLeReadMaximumDataLength.UserFields.SupportedMaxTxOctets, 16), "", "0x001B", "0x00FB", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Supported_Max_Tx_Time", "Maximum time, in microseconds, that the local Controller supports for transmission of a single Link Layer Data Channel PDU. Range 0x0148–0x4290 (all other values reserved for future use)", 16, FormatValue(commandCompleteForLeReadMaximumDataLength.UserFields.SupportedMaxTxTime, 16), "", "0x0148", "0x4290", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Supported_Max_Rx_Octets", "Maximum number of payload octets that the local Controller supports for reception of a single Link Layer Data Channel PDU. Range 0x001B-0x00FB (0x0000 - 0x001A and 0x00FC - 0xFFFF Reserved for future use)", 16, FormatValue(commandCompleteForLeReadMaximumDataLength.UserFields.SupportedMaxRxOctets, 16), "", "0x001B", "0x00FB", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Supported_Max_Rx_Time", "Maximum time, in microseconds, that the local Controller supports for reception of a single Link Layer Data Channel PDU. Range 0x0148–0x4290 (all other values reserved for future use)", 16, FormatValue(commandCompleteForLeReadMaximumDataLength.UserFields.SupportedMaxRxTime, 16), "", "0x0148", "0x4290", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		CommandCompleteForLeReadMaximumDataLength commandCompleteForLeReadMaximumDataLength = (CommandCompleteForLeReadMaximumDataLength)packet;
		int num = -1;
		if (index == ++num)
		{
			commandCompleteForLeReadMaximumDataLength.UserFields.NumHciCommandPackets = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field CommandOpcode");
		}
		if (index == ++num)
		{
			commandCompleteForLeReadMaximumDataLength.UserFields.Status = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			commandCompleteForLeReadMaximumDataLength.UserFields.SupportedMaxTxOctets = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			commandCompleteForLeReadMaximumDataLength.UserFields.SupportedMaxTxTime = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			commandCompleteForLeReadMaximumDataLength.UserFields.SupportedMaxRxOctets = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			commandCompleteForLeReadMaximumDataLength.UserFields.SupportedMaxRxTime = Convert.ToUInt32(value, 16);
		}
	}
}
