using System;
using System.Collections.Generic;
using System.Text;
using QCRPG.Framework;

namespace QCRPG.TSL.NFC.Packets;

public class CoreInitRsp : PacketBase
{
	public class UserFieldsWrapper
	{
		public class NfccFeaturesEnumCollection
		{
			public enum DiscoveryConfigurationModeEnum
			{
				DHOnly,
				DHAndOther,
				RFU,
				InvalidDiscoveryConfigurationModeValue
			}

			public static class DiscoveryConfigurationModeInfo
			{
				public static DiscoveryConfigurationModeEnum ValueToDiscoveryConfigurationMode(uint value)
				{
					switch (value)
					{
					case 0u:
						return DiscoveryConfigurationModeEnum.DHOnly;
					case 1u:
						return DiscoveryConfigurationModeEnum.DHAndOther;
					default:
						if (value >= 2 && value <= 3)
						{
							return DiscoveryConfigurationModeEnum.RFU;
						}
						return DiscoveryConfigurationModeEnum.InvalidDiscoveryConfigurationModeValue;
					}
				}

				public static uint DiscoveryConfigurationModeToValue(DiscoveryConfigurationModeEnum enumItem)
				{
					return enumItem switch
					{
						DiscoveryConfigurationModeEnum.DHOnly => 0u, 
						DiscoveryConfigurationModeEnum.DHAndOther => 1u, 
						DiscoveryConfigurationModeEnum.RFU => 2u, 
						_ => uint.MaxValue, 
					};
				}

				public static string DiscoveryConfigurationModeToString(DiscoveryConfigurationModeEnum enumItem)
				{
					return enumItem switch
					{
						DiscoveryConfigurationModeEnum.DHOnly => "The DH is the only entity that configures the NFCC.", 
						DiscoveryConfigurationModeEnum.DHAndOther => "The NFCC can receive configurations from the DH and other NFCEEs.", 
						DiscoveryConfigurationModeEnum.RFU => "RFU", 
						_ => "Invalid DiscoveryConfigurationMode Value", 
					};
				}

				public static string DiscoveryConfigurationModeToDescription()
				{
					StringBuilder stringBuilder = new StringBuilder();
					stringBuilder.AppendLine("0x0 = The DH is the only entity that configures the NFCC.");
					stringBuilder.AppendLine("0x1 = The NFCC can receive configurations from the DH and other NFCEEs.");
					stringBuilder.AppendLine("0x2-0x3 = RFU");
					return stringBuilder.ToString();
				}
			}

			private SupportBitEnum _DiscoveryFrequencyConfigurationInRfDiscoverCmd;

			private DiscoveryConfigurationModeEnum _DiscoveryConfigurationMode;

			private SupportBitEnum _TechnologyBasedRouting;

			private SupportBitEnum _ProtocolBasedRouting;

			private SupportBitEnum _AidBasedRouting;

			private SupportBitEnum _BatteryOffState;

			private SupportBitEnum _SwitchedOffState;

			public SupportBitEnum DiscoveryFrequencyConfigurationInRfDiscoverCmd
			{
				get
				{
					return _DiscoveryFrequencyConfigurationInRfDiscoverCmd;
				}
				set
				{
					_DiscoveryFrequencyConfigurationInRfDiscoverCmd = value;
				}
			}

			public DiscoveryConfigurationModeEnum DiscoveryConfigurationMode
			{
				get
				{
					return _DiscoveryConfigurationMode;
				}
				set
				{
					_DiscoveryConfigurationMode = value;
				}
			}

			public SupportBitEnum TechnologyBasedRouting
			{
				get
				{
					return _TechnologyBasedRouting;
				}
				set
				{
					_TechnologyBasedRouting = value;
				}
			}

			public SupportBitEnum ProtocolBasedRouting
			{
				get
				{
					return _ProtocolBasedRouting;
				}
				set
				{
					_ProtocolBasedRouting = value;
				}
			}

			public SupportBitEnum AidBasedRouting
			{
				get
				{
					return _AidBasedRouting;
				}
				set
				{
					_AidBasedRouting = value;
				}
			}

			public SupportBitEnum BatteryOffState
			{
				get
				{
					return _BatteryOffState;
				}
				set
				{
					_BatteryOffState = value;
				}
			}

			public SupportBitEnum SwitchedOffState
			{
				get
				{
					return _SwitchedOffState;
				}
				set
				{
					_SwitchedOffState = value;
				}
			}
		}

		public static class NfccFeaturesInfo
		{
			public static NfccFeaturesEnumCollection ValueToNfccFeatures(uint value)
			{
				NfccFeaturesEnumCollection nfccFeaturesEnumCollection = new NfccFeaturesEnumCollection();
				nfccFeaturesEnumCollection.DiscoveryFrequencyConfigurationInRfDiscoverCmd = SupportBitInfo.ValueToSupportBit(value & 1u);
				nfccFeaturesEnumCollection.DiscoveryConfigurationMode = NfccFeaturesEnumCollection.DiscoveryConfigurationModeInfo.ValueToDiscoveryConfigurationMode((value & 6) >> 1);
				nfccFeaturesEnumCollection.TechnologyBasedRouting = SupportBitInfo.ValueToSupportBit((value & 0x200) >> 9);
				nfccFeaturesEnumCollection.ProtocolBasedRouting = SupportBitInfo.ValueToSupportBit((value & 0x400) >> 10);
				nfccFeaturesEnumCollection.AidBasedRouting = SupportBitInfo.ValueToSupportBit((value & 0x800) >> 11);
				nfccFeaturesEnumCollection.BatteryOffState = SupportBitInfo.ValueToSupportBit((value & 0x10000) >> 16);
				nfccFeaturesEnumCollection.SwitchedOffState = SupportBitInfo.ValueToSupportBit((value & 0x20000) >> 17);
				return nfccFeaturesEnumCollection;
			}

			public static uint NfccFeaturesToValue(NfccFeaturesEnumCollection enumCollection)
			{
				uint num = 0u;
				num |= SupportBitInfo.SupportBitToValue(enumCollection.DiscoveryFrequencyConfigurationInRfDiscoverCmd);
				num |= NfccFeaturesEnumCollection.DiscoveryConfigurationModeInfo.DiscoveryConfigurationModeToValue(enumCollection.DiscoveryConfigurationMode) << 1;
				num |= SupportBitInfo.SupportBitToValue(enumCollection.TechnologyBasedRouting) << 9;
				num |= SupportBitInfo.SupportBitToValue(enumCollection.ProtocolBasedRouting) << 10;
				num |= SupportBitInfo.SupportBitToValue(enumCollection.AidBasedRouting) << 11;
				num |= SupportBitInfo.SupportBitToValue(enumCollection.BatteryOffState) << 16;
				return num | (SupportBitInfo.SupportBitToValue(enumCollection.SwitchedOffState) << 17);
			}

			public static string NfccFeaturesToString(NfccFeaturesEnumCollection enumCollection)
			{
				string text = "";
				text = text + "Discovery Frequency configuration in RF_DISCOVER_CMD: " + SupportBitInfo.SupportBitToString(enumCollection.DiscoveryFrequencyConfigurationInRfDiscoverCmd) + "\r\n";
				text = text + "Discovery Configuration Mode: " + NfccFeaturesEnumCollection.DiscoveryConfigurationModeInfo.DiscoveryConfigurationModeToString(enumCollection.DiscoveryConfigurationMode) + "\r\n";
				text = text + "Technology based Routing: " + SupportBitInfo.SupportBitToString(enumCollection.TechnologyBasedRouting) + "\r\n";
				text = text + "Protocol based routing: " + SupportBitInfo.SupportBitToString(enumCollection.ProtocolBasedRouting) + "\r\n";
				text = text + "AID based routing: " + SupportBitInfo.SupportBitToString(enumCollection.AidBasedRouting) + "\r\n";
				text = text + "Battery Off state: " + SupportBitInfo.SupportBitToString(enumCollection.BatteryOffState) + "\r\n";
				text = text + "Switched Off state: " + SupportBitInfo.SupportBitToString(enumCollection.SwitchedOffState) + "\r\n";
				return text.TrimEnd('\r', '\n');
			}

			public static string NfccFeaturesToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("Bit 0: Discovery Frequency configuration in RF_DISCOVER_CMD");
				stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
				stringBuilder.AppendLine("Bits 2-1: Discovery Configuration Mode");
				stringBuilder.AppendLine(NfccFeaturesEnumCollection.DiscoveryConfigurationModeInfo.DiscoveryConfigurationModeToDescription());
				stringBuilder.AppendLine("Bits 8-3: RFU");
				stringBuilder.AppendLine("Bit 9: Technology based Routing");
				stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
				stringBuilder.AppendLine("Bit 10: Protocol based routing");
				stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
				stringBuilder.AppendLine("Bit 11: AID based routing");
				stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
				stringBuilder.AppendLine("Bits 15-12: RFU");
				stringBuilder.AppendLine("Bit 16: Battery Off state");
				stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
				stringBuilder.AppendLine("Bit 17: Switched Off state");
				stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
				stringBuilder.AppendLine("Bits 23-18: RFU");
				stringBuilder.AppendLine("Bits 31-24: Reserved for proprietary capabilities");
				return stringBuilder.ToString();
			}
		}

		public enum MaxLogicalConnectionsEnum
		{
			MAX_LOGICAL_CONNECTIONS_0,
			MAX_LOGICAL_CONNECTIONS_1,
			MAX_LOGICAL_CONNECTIONS_2,
			MAX_LOGICAL_CONNECTIONS_3,
			MAX_LOGICAL_CONNECTIONS_4,
			MAX_LOGICAL_CONNECTIONS_5,
			MAX_LOGICAL_CONNECTIONS_6,
			MAX_LOGICAL_CONNECTIONS_7,
			MAX_LOGICAL_CONNECTIONS_8,
			MAX_LOGICAL_CONNECTIONS_9,
			MAX_LOGICAL_CONNECTIONS_10,
			MAX_LOGICAL_CONNECTIONS_11,
			MAX_LOGICAL_CONNECTIONS_12,
			MAX_LOGICAL_CONNECTIONS_13,
			MAX_LOGICAL_CONNECTIONS_14,
			RFU,
			InvalidMaxLogicalConnectionsValue
		}

		public static class MaxLogicalConnectionsInfo
		{
			public static MaxLogicalConnectionsEnum ValueToMaxLogicalConnections(uint value)
			{
				switch (value)
				{
				case 0u:
					return MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_0;
				case 1u:
					return MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_1;
				case 2u:
					return MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_2;
				case 3u:
					return MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_3;
				case 4u:
					return MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_4;
				case 5u:
					return MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_5;
				case 6u:
					return MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_6;
				case 7u:
					return MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_7;
				case 8u:
					return MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_8;
				case 9u:
					return MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_9;
				case 10u:
					return MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_10;
				case 11u:
					return MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_11;
				case 12u:
					return MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_12;
				case 13u:
					return MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_13;
				case 14u:
					return MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_14;
				default:
					if (value >= 15 && value <= 255)
					{
						return MaxLogicalConnectionsEnum.RFU;
					}
					return MaxLogicalConnectionsEnum.InvalidMaxLogicalConnectionsValue;
				}
			}

			public static uint MaxLogicalConnectionsToValue(MaxLogicalConnectionsEnum enumItem)
			{
				return enumItem switch
				{
					MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_0 => 0u, 
					MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_1 => 1u, 
					MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_2 => 2u, 
					MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_3 => 3u, 
					MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_4 => 4u, 
					MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_5 => 5u, 
					MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_6 => 6u, 
					MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_7 => 7u, 
					MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_8 => 8u, 
					MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_9 => 9u, 
					MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_10 => 10u, 
					MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_11 => 11u, 
					MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_12 => 12u, 
					MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_13 => 13u, 
					MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_14 => 14u, 
					MaxLogicalConnectionsEnum.RFU => 15u, 
					_ => uint.MaxValue, 
				};
			}

			public static string MaxLogicalConnectionsToString(MaxLogicalConnectionsEnum enumItem)
			{
				return enumItem switch
				{
					MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_0 => "MAX_LOGICAL_CONNECTIONS_0", 
					MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_1 => "MAX_LOGICAL_CONNECTIONS_1", 
					MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_2 => "MAX_LOGICAL_CONNECTIONS_2", 
					MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_3 => "MAX_LOGICAL_CONNECTIONS_3", 
					MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_4 => "MAX_LOGICAL_CONNECTIONS_4", 
					MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_5 => "MAX_LOGICAL_CONNECTIONS_5", 
					MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_6 => "MAX_LOGICAL_CONNECTIONS_6", 
					MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_7 => "MAX_LOGICAL_CONNECTIONS_7", 
					MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_8 => "MAX_LOGICAL_CONNECTIONS_8", 
					MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_9 => "MAX_LOGICAL_CONNECTIONS_9", 
					MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_10 => "MAX_LOGICAL_CONNECTIONS_10", 
					MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_11 => "MAX_LOGICAL_CONNECTIONS_11", 
					MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_12 => "MAX_LOGICAL_CONNECTIONS_12", 
					MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_13 => "MAX_LOGICAL_CONNECTIONS_13", 
					MaxLogicalConnectionsEnum.MAX_LOGICAL_CONNECTIONS_14 => "MAX_LOGICAL_CONNECTIONS_14", 
					MaxLogicalConnectionsEnum.RFU => "RFU", 
					_ => "Invalid MaxLogicalConnections Value", 
				};
			}

			public static string MaxLogicalConnectionsToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("0x0 = MAX_LOGICAL_CONNECTIONS_0");
				stringBuilder.AppendLine("0x1 = MAX_LOGICAL_CONNECTIONS_1");
				stringBuilder.AppendLine("0x2 = MAX_LOGICAL_CONNECTIONS_2");
				stringBuilder.AppendLine("0x3 = MAX_LOGICAL_CONNECTIONS_3");
				stringBuilder.AppendLine("0x4 = MAX_LOGICAL_CONNECTIONS_4");
				stringBuilder.AppendLine("0x5 = MAX_LOGICAL_CONNECTIONS_5");
				stringBuilder.AppendLine("0x6 = MAX_LOGICAL_CONNECTIONS_6");
				stringBuilder.AppendLine("0x7 = MAX_LOGICAL_CONNECTIONS_7");
				stringBuilder.AppendLine("0x8 = MAX_LOGICAL_CONNECTIONS_8");
				stringBuilder.AppendLine("0x9 = MAX_LOGICAL_CONNECTIONS_9");
				stringBuilder.AppendLine("0xA = MAX_LOGICAL_CONNECTIONS_10");
				stringBuilder.AppendLine("0xB = MAX_LOGICAL_CONNECTIONS_11");
				stringBuilder.AppendLine("0xC = MAX_LOGICAL_CONNECTIONS_12");
				stringBuilder.AppendLine("0xD = MAX_LOGICAL_CONNECTIONS_13");
				stringBuilder.AppendLine("0xE = MAX_LOGICAL_CONNECTIONS_14");
				stringBuilder.AppendLine("0xF-0xFF = RFU");
				return stringBuilder.ToString();
			}
		}

		private uint _Status;

		private uint _NfccFeatures;

		private uint _NumberOfSupportedRfInterfaces;

		private List<uint> _SupportedRfInterfaceList = new List<uint>();

		private uint _MaxLogicalConnections;

		private uint _MaxRoutingTableSize;

		private uint _MaxControlPacketPayloadSize = 32u;

		private uint _MaxSizeForLargeParameters;

		private uint _ManufacturerId;

		private uint _ManufacturerSpecificInformation;

		public uint Status
		{
			get
			{
				return _Status;
			}
			set
			{
				if (value > 255)
				{
					throw new Exception("Maximum possible value for Status is 0xFF");
				}
				_Status = value;
			}
		}

		public uint NfccFeatures
		{
			get
			{
				return _NfccFeatures;
			}
			set
			{
				_NfccFeatures = value;
			}
		}

		public uint NumberOfSupportedRfInterfaces
		{
			get
			{
				return _NumberOfSupportedRfInterfaces;
			}
			set
			{
				if (value > 255)
				{
					throw new Exception("Maximum possible value for NumberOfSupportedRfInterfaces is 0xFF");
				}
				_NumberOfSupportedRfInterfaces = value;
				while (_SupportedRfInterfaceList.Count < _NumberOfSupportedRfInterfaces)
				{
					_SupportedRfInterfaceList.Add(0u);
				}
				while (_SupportedRfInterfaceList.Count > _NumberOfSupportedRfInterfaces)
				{
					_SupportedRfInterfaceList.RemoveAt(_SupportedRfInterfaceList.Count - 1);
				}
			}
		}

		public List<uint> SupportedRfInterfaceList => _SupportedRfInterfaceList;

		public uint MaxLogicalConnections
		{
			get
			{
				return _MaxLogicalConnections;
			}
			set
			{
				if (value > 255)
				{
					throw new Exception("Maximum possible value for MaxLogicalConnections is 0xFF");
				}
				_MaxLogicalConnections = value;
			}
		}

		public uint MaxRoutingTableSize
		{
			get
			{
				return _MaxRoutingTableSize;
			}
			set
			{
				if (value > 65535)
				{
					throw new Exception("Maximum possible value for MaxRoutingTableSize is 0xFFFF");
				}
				_MaxRoutingTableSize = value;
			}
		}

		public uint MaxControlPacketPayloadSize
		{
			get
			{
				return _MaxControlPacketPayloadSize;
			}
			set
			{
				if (value > 255)
				{
					throw new Exception("Maximum possible value for MaxControlPacketPayloadSize is 0xFF");
				}
				_MaxControlPacketPayloadSize = value;
			}
		}

		public uint MaxSizeForLargeParameters
		{
			get
			{
				return _MaxSizeForLargeParameters;
			}
			set
			{
				if (value > 65535)
				{
					throw new Exception("Maximum possible value for MaxSizeForLargeParameters is 0xFFFF");
				}
				_MaxSizeForLargeParameters = value;
			}
		}

		public uint ManufacturerId
		{
			get
			{
				return _ManufacturerId;
			}
			set
			{
				if (value > 255)
				{
					throw new Exception("Maximum possible value for ManufacturerId is 0xFF");
				}
				_ManufacturerId = value;
			}
		}

		public uint ManufacturerSpecificInformation
		{
			get
			{
				return _ManufacturerSpecificInformation;
			}
			set
			{
				_ManufacturerSpecificInformation = value;
			}
		}

		public StatusCodesEnum GetStatusAsStatusCodesEnum()
		{
			return StatusCodesInfo.ValueToStatusCodes(_Status);
		}

		public void SetStatusAsStatusCodesEnum(StatusCodesEnum enumItem)
		{
			Status = StatusCodesInfo.StatusCodesToValue(enumItem);
		}

		public NfccFeaturesEnumCollection GetNfccFeaturesAsNfccFeaturesEnumCollection()
		{
			return NfccFeaturesInfo.ValueToNfccFeatures(_NfccFeatures);
		}

		public void SetNfccFeaturesAsNfccFeaturesEnumCollection(NfccFeaturesEnumCollection enumCollection)
		{
			NfccFeatures = NfccFeaturesInfo.NfccFeaturesToValue(enumCollection);
		}

		public RfInterfacesEnum GetSupportedRfInterfaceAsRfInterfacesEnum(int index)
		{
			return RfInterfacesInfo.ValueToRfInterfaces(_SupportedRfInterfaceList[index]);
		}

		public void SetSupportedRfInterfaceAsRfInterfacesEnum(int index, RfInterfacesEnum enumItem)
		{
			_SupportedRfInterfaceList[index] = RfInterfacesInfo.RfInterfacesToValue(enumItem);
		}

		public MaxLogicalConnectionsEnum GetMaxLogicalConnectionsAsMaxLogicalConnectionsEnum()
		{
			return MaxLogicalConnectionsInfo.ValueToMaxLogicalConnections(_MaxLogicalConnections);
		}

		public void SetMaxLogicalConnectionsAsMaxLogicalConnectionsEnum(MaxLogicalConnectionsEnum enumItem)
		{
			MaxLogicalConnections = MaxLogicalConnectionsInfo.MaxLogicalConnectionsToValue(enumItem);
		}
	}

	private const uint _Mt = 2u;

	private const uint _Gid = 0u;

	private const uint _Oid = 1u;

	private Type[] expectedResponseTypes = new Type[0];

	private PacketInfoBase info;

	private uint _Pbf;

	private uint _Rfu;

	private uint _PayloadLength;

	public UserFieldsWrapper _UserFields = new UserFieldsWrapper();

	public override PacketType Type => PacketType.Response;

	public override Type[] ExpectedResponseTypes => expectedResponseTypes;

	public override PacketInfoBase Info
	{
		get
		{
			if (info == null)
			{
				info = new CoreInitRspInfo(this);
			}
			return info;
		}
	}

	public uint Mt => 2u;

	public uint Pbf => _Pbf;

	public uint Gid => 0u;

	public uint Rfu => _Rfu;

	public uint Oid => 1u;

	public uint PayloadLength
	{
		get
		{
			ToBitString();
			return _PayloadLength;
		}
	}

	public UserFieldsWrapper UserFields => _UserFields;

	public override void SetDefaultValues()
	{
		UserFields.MaxControlPacketPayloadSize = 32u;
	}

	protected override bool FromBitBuilder(ref BitBuilder bitBuilder)
	{
		if (bitBuilder.RemoveBitsAsUint(3) != Mt)
		{
			return false;
		}
		_Pbf = bitBuilder.RemoveBitsAsUint(1);
		if (bitBuilder.RemoveBitsAsUint(4) != Gid)
		{
			return false;
		}
		_Rfu = bitBuilder.RemoveBitsAsUint(2);
		if (bitBuilder.RemoveBitsAsUint(6) != Oid)
		{
			return false;
		}
		_PayloadLength = bitBuilder.RemoveBitsAsUint(8);
		int numberOfBits = bitBuilder.GetNumberOfBits();
		if (numberOfBits > _PayloadLength * 8 + 7)
		{
			return false;
		}
		if (numberOfBits < _PayloadLength * 8)
		{
			return false;
		}
		UserFields.Status = bitBuilder.RemoveBitsAsUint(8);
		UserFields.NfccFeatures = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.NumberOfSupportedRfInterfaces = bitBuilder.RemoveBitsAsUint(8);
		for (int i = 0; i < UserFields.SupportedRfInterfaceList.Count; i++)
		{
			UserFields.SupportedRfInterfaceList[i] = bitBuilder.RemoveBitsAsUint(8);
		}
		UserFields.MaxLogicalConnections = bitBuilder.RemoveBitsAsUint(8);
		UserFields.MaxRoutingTableSize = bitBuilder.RemoveBitsAsUintLittleEndian(16);
		UserFields.MaxControlPacketPayloadSize = bitBuilder.RemoveBitsAsUint(8);
		UserFields.MaxSizeForLargeParameters = bitBuilder.RemoveBitsAsUintLittleEndian(16);
		UserFields.ManufacturerId = bitBuilder.RemoveBitsAsUint(8);
		UserFields.ManufacturerSpecificInformation = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		if (bitBuilder.GetNumberOfBits() > 7)
		{
			return false;
		}
		return true;
	}

	public override string ToBitString()
	{
		BitBuilder bitBuilder = new BitBuilder();
		bitBuilder.AddBitsAsUint(Mt, 3);
		bitBuilder.AddBitsAsUint(Pbf, 1);
		bitBuilder.AddBitsAsUint(Gid, 4);
		bitBuilder.AddBitsAsUint(Rfu, 2);
		bitBuilder.AddBitsAsUint(Oid, 6);
		int numberOfBits = bitBuilder.GetNumberOfBits();
		bitBuilder.AddBitsAsUint(0u, 8);
		bitBuilder.AddBitsAsUint(UserFields.Status, 8);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.NfccFeatures, 32);
		bitBuilder.AddBitsAsUint(UserFields.NumberOfSupportedRfInterfaces, 8);
		for (int i = 0; i < UserFields.SupportedRfInterfaceList.Count; i++)
		{
			if (UserFields.SupportedRfInterfaceList[i] > 255)
			{
				throw new Exception("Maximum possible value for SupportedRfInterface is 0xFF");
			}
			bitBuilder.AddBitsAsUint(UserFields.SupportedRfInterfaceList[i], 8);
		}
		bitBuilder.AddBitsAsUint(UserFields.MaxLogicalConnections, 8);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.MaxRoutingTableSize, 16);
		bitBuilder.AddBitsAsUint(UserFields.MaxControlPacketPayloadSize, 8);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.MaxSizeForLargeParameters, 16);
		bitBuilder.AddBitsAsUint(UserFields.ManufacturerId, 8);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.ManufacturerSpecificInformation, 32);
		_PayloadLength = (uint)((bitBuilder.GetNumberOfBits() - numberOfBits - 8) / 8);
		if ((bitBuilder.GetNumberOfBits() - numberOfBits - 8) % 8 != 0)
		{
			_PayloadLength++;
		}
		bitBuilder.ChangeBitsAsUint(numberOfBits, _PayloadLength, 8);
		return bitBuilder.ToString();
	}

	public override List<string> GetWarnings()
	{
		List<string> list = new List<string>();
		if (UserFields.MaxControlPacketPayloadSize < 32)
		{
			list.Add("Minimum allowed value for Max Control Packet Payload Size is 0x20");
		}
		return list;
	}
}
