using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class CommandCompleteForReadAfhChannelMapInfo : PacketInfoBase
{
	public override string Name => "Command Complete For Read Afh Channel Map";

	public override string DisplayGroup => "Status Parameters";

	public CommandCompleteForReadAfhChannelMapInfo(CommandCompleteForReadAfhChannelMap packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		CommandCompleteForReadAfhChannelMap commandCompleteForReadAfhChannelMap = (CommandCompleteForReadAfhChannelMap)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Num HCI Command Packets", "", 8, FormatValue(commandCompleteForReadAfhChannelMap.UserFields.NumHciCommandPackets, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Command OpCode", CommandOpcodeInfo.CommandOpcodeToDescription(), 16, FormatValue(commandCompleteForReadAfhChannelMap.UserFields.CommandOpcode, 16), CommandOpcodeInfo.CommandOpcodeToString(CommandOpcodeInfo.ValueToCommandOpcode(commandCompleteForReadAfhChannelMap.UserFields.CommandOpcode)), "", "", settable: false, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(commandCompleteForReadAfhChannelMap.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(commandCompleteForReadAfhChannelMap.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Connection_Handle", "The Connection_Handle for the connection for which the Channel Map is to be read. Range: 0x0000-0x0EFF (0x0F00 - 0x0FFF Reserved for future use)", 16, FormatValue(commandCompleteForReadAfhChannelMap.UserFields.ConnectionHandle, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("AFH_Mode", CommandCompleteForReadAfhChannelMap.UserFieldsWrapper.AfhModeInfo.AfhModeToDescription(), 8, FormatValue(commandCompleteForReadAfhChannelMap.UserFields.AfhMode, 8), CommandCompleteForReadAfhChannelMap.UserFieldsWrapper.AfhModeInfo.AfhModeToString(CommandCompleteForReadAfhChannelMap.UserFieldsWrapper.AfhModeInfo.ValueToAfhMode(commandCompleteForReadAfhChannelMap.UserFields.AfhMode)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("AFH_Channel_Map", "If AFH_Mode is AFH enabled then this parameter contains 79 1-bit fields, otherwise the contents are reserved. The nth such field (in the range 0 to 78) contains the value for channel n: Channel n is unused = 0, Channel n is used = 1. Range: 0x00000000000000000000-0x7FFFFFFFFFFFFFFFFFFF (0x80000000000000000000-0xFFFFFFFFFFFFFFFFFFFF Reserved for future use).", commandCompleteForReadAfhChannelMap.UserFields.AfhChannelMapList.Count * 8, FormatValue(commandCompleteForReadAfhChannelMap.UserFields.AfhChannelMapList, commandCompleteForReadAfhChannelMap.UserFields.AfhChannelMapList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		CommandCompleteForReadAfhChannelMap commandCompleteForReadAfhChannelMap = (CommandCompleteForReadAfhChannelMap)packet;
		int num = -1;
		if (index == ++num)
		{
			commandCompleteForReadAfhChannelMap.UserFields.NumHciCommandPackets = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field CommandOpcode");
		}
		if (index == ++num)
		{
			commandCompleteForReadAfhChannelMap.UserFields.Status = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			commandCompleteForReadAfhChannelMap.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			commandCompleteForReadAfhChannelMap.UserFields.AfhMode = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, commandCompleteForReadAfhChannelMap.UserFields.AfhChannelMapList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				commandCompleteForReadAfhChannelMap.UserFields.AfhChannelMapList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
