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

namespace QCRPG.TSL.NFC.Packets;

public class RfIntfActivatedNtf : PacketBase
{
	public class UserFieldsWrapper
	{
		private uint _RfDiscoveryId;

		private uint _RfInterface;

		private uint _RfProtocol;

		private uint _ActivationRfTechnologyAndMode;

		private uint _MaxDataPacketPayloadSize;

		private uint _InitialNumberOfCredits;

		private uint _LengthOfRfTechnologySpecificParameters;

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

		private uint _DataExchangeRfTechnologyAndMode;

		private uint _DataExchangeTransmitBitRate;

		private uint _DataExchangeReceiveBitRate;

		private uint _LengthOfActivationParameters;

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

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

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

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

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

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

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

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

		public List<uint> RfTechnologySpecificParametersList => _RfTechnologySpecificParametersList;

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

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

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

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

		public List<uint> ActivationParametersList => _ActivationParametersList;

		public RfDiscoveryIdEnum GetRfDiscoveryIdAsRfDiscoveryIdEnum()
		{
			return RfDiscoveryIdInfo.ValueToRfDiscoveryId(_RfDiscoveryId);
		}

		public void SetRfDiscoveryIdAsRfDiscoveryIdEnum(RfDiscoveryIdEnum enumItem)
		{
			RfDiscoveryId = RfDiscoveryIdInfo.RfDiscoveryIdToValue(enumItem);
		}

		public RfInterfacesEnum GetRfInterfaceAsRfInterfacesEnum()
		{
			return RfInterfacesInfo.ValueToRfInterfaces(_RfInterface);
		}

		public void SetRfInterfaceAsRfInterfacesEnum(RfInterfacesEnum enumItem)
		{
			RfInterface = RfInterfacesInfo.RfInterfacesToValue(enumItem);
		}

		public RfProtocolsEnum GetRfProtocolAsRfProtocolsEnum()
		{
			return RfProtocolsInfo.ValueToRfProtocols(_RfProtocol);
		}

		public void SetRfProtocolAsRfProtocolsEnum(RfProtocolsEnum enumItem)
		{
			RfProtocol = RfProtocolsInfo.RfProtocolsToValue(enumItem);
		}

		public RfTechnologyAndModeEnum GetActivationRfTechnologyAndModeAsRfTechnologyAndModeEnum()
		{
			return RfTechnologyAndModeInfo.ValueToRfTechnologyAndMode(_ActivationRfTechnologyAndMode);
		}

		public void SetActivationRfTechnologyAndModeAsRfTechnologyAndModeEnum(RfTechnologyAndModeEnum enumItem)
		{
			ActivationRfTechnologyAndMode = RfTechnologyAndModeInfo.RfTechnologyAndModeToValue(enumItem);
		}

		public RfTechnologyAndModeEnum GetDataExchangeRfTechnologyAndModeAsRfTechnologyAndModeEnum()
		{
			return RfTechnologyAndModeInfo.ValueToRfTechnologyAndMode(_DataExchangeRfTechnologyAndMode);
		}

		public void SetDataExchangeRfTechnologyAndModeAsRfTechnologyAndModeEnum(RfTechnologyAndModeEnum enumItem)
		{
			DataExchangeRfTechnologyAndMode = RfTechnologyAndModeInfo.RfTechnologyAndModeToValue(enumItem);
		}

		public BitRatesEnum GetDataExchangeTransmitBitRateAsBitRatesEnum()
		{
			return BitRatesInfo.ValueToBitRates(_DataExchangeTransmitBitRate);
		}

		public void SetDataExchangeTransmitBitRateAsBitRatesEnum(BitRatesEnum enumItem)
		{
			DataExchangeTransmitBitRate = BitRatesInfo.BitRatesToValue(enumItem);
		}

		public BitRatesEnum GetDataExchangeReceiveBitRateAsBitRatesEnum()
		{
			return BitRatesInfo.ValueToBitRates(_DataExchangeReceiveBitRate);
		}

		public void SetDataExchangeReceiveBitRateAsBitRatesEnum(BitRatesEnum enumItem)
		{
			DataExchangeReceiveBitRate = BitRatesInfo.BitRatesToValue(enumItem);
		}
	}

	private const uint _Mt = 3u;

	private const uint _Gid = 1u;

	private const uint _Oid = 5u;

	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.Notification;

	public override Type[] ExpectedResponseTypes => expectedResponseTypes;

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

	public uint Mt => 3u;

	public uint Pbf => _Pbf;

	public uint Gid => 1u;

	public uint Rfu => _Rfu;

	public uint Oid => 5u;

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

	public UserFieldsWrapper UserFields => _UserFields;

	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.RfDiscoveryId = bitBuilder.RemoveBitsAsUint(8);
		UserFields.RfInterface = bitBuilder.RemoveBitsAsUint(8);
		UserFields.RfProtocol = bitBuilder.RemoveBitsAsUint(8);
		UserFields.ActivationRfTechnologyAndMode = bitBuilder.RemoveBitsAsUint(8);
		UserFields.MaxDataPacketPayloadSize = bitBuilder.RemoveBitsAsUint(8);
		UserFields.InitialNumberOfCredits = bitBuilder.RemoveBitsAsUint(8);
		UserFields.LengthOfRfTechnologySpecificParameters = bitBuilder.RemoveBitsAsUint(8);
		for (int i = 0; i < UserFields.RfTechnologySpecificParametersList.Count; i++)
		{
			UserFields.RfTechnologySpecificParametersList[i] = bitBuilder.RemoveBitsAsUint(8);
		}
		UserFields.DataExchangeRfTechnologyAndMode = bitBuilder.RemoveBitsAsUint(8);
		UserFields.DataExchangeTransmitBitRate = bitBuilder.RemoveBitsAsUint(8);
		UserFields.DataExchangeReceiveBitRate = bitBuilder.RemoveBitsAsUint(8);
		UserFields.LengthOfActivationParameters = bitBuilder.RemoveBitsAsUint(8);
		for (int j = 0; j < UserFields.ActivationParametersList.Count; j++)
		{
			UserFields.ActivationParametersList[j] = bitBuilder.RemoveBitsAsUint(8);
		}
		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.RfDiscoveryId, 8);
		bitBuilder.AddBitsAsUint(UserFields.RfInterface, 8);
		bitBuilder.AddBitsAsUint(UserFields.RfProtocol, 8);
		bitBuilder.AddBitsAsUint(UserFields.ActivationRfTechnologyAndMode, 8);
		bitBuilder.AddBitsAsUint(UserFields.MaxDataPacketPayloadSize, 8);
		bitBuilder.AddBitsAsUint(UserFields.InitialNumberOfCredits, 8);
		bitBuilder.AddBitsAsUint(UserFields.LengthOfRfTechnologySpecificParameters, 8);
		for (int i = 0; i < UserFields.RfTechnologySpecificParametersList.Count; i++)
		{
			if (UserFields.RfTechnologySpecificParametersList[i] > 255)
			{
				throw new Exception("UserFields.RfTechnologySpecificParametersList[i] is > 0xFF");
			}
			bitBuilder.AddBitsAsUint(UserFields.RfTechnologySpecificParametersList[i], 8);
		}
		bitBuilder.AddBitsAsUint(UserFields.DataExchangeRfTechnologyAndMode, 8);
		bitBuilder.AddBitsAsUint(UserFields.DataExchangeTransmitBitRate, 8);
		bitBuilder.AddBitsAsUint(UserFields.DataExchangeReceiveBitRate, 8);
		bitBuilder.AddBitsAsUint(UserFields.LengthOfActivationParameters, 8);
		for (int j = 0; j < UserFields.ActivationParametersList.Count; j++)
		{
			if (UserFields.ActivationParametersList[j] > 255)
			{
				throw new Exception("UserFields.ActivationParametersList[i] is > 0xFF");
			}
			bitBuilder.AddBitsAsUint(UserFields.ActivationParametersList[j], 8);
		}
		_PayloadLength = (uint)((bitBuilder.GetNumberOfBits() - numberOfBits - 8) / 8);
		if ((bitBuilder.GetNumberOfBits() - numberOfBits - 8) % 8 != 0)
		{
			_PayloadLength++;
		}
		bitBuilder.ChangeBitsAsUint(numberOfBits, _PayloadLength, 8);
		return bitBuilder.ToString();
	}
}
