using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class ProdTestStatsEvent : PacketBase
{
	public class UserFieldsWrapper
	{
		private const uint _Command = 4u;

		private uint _ReceivedPackets;

		private uint _Ch1PacketsReceived;

		private uint _Ch1PacketAccessErrorCode;

		private uint _Ch1HecErrors;

		private uint _Ch1CrcErrors;

		private uint _Ch1TotalPacketBitErrors;

		private uint _Ch1FirstHalfBitErrors;

		private uint _Ch1LastHalfBitErrors;

		private uint _Ch1RssiReading;

		private uint _Ch2PacketsReceived;

		private uint _Ch2PacketAccessErrorCode;

		private uint _Ch2HecErrors;

		private uint _Ch2CrcErrors;

		private uint _Ch2TotalPacketBitErrors;

		private uint _Ch2FirstHalfBitErrors;

		private uint _Ch2LastHalfBitErrors;

		private uint _Ch2RssiReading;

		private uint _Ch3PacketsReceived;

		private uint _Ch3PacketAccessErrorCode;

		private uint _Ch3HecErrors;

		private uint _Ch3CrcErrors;

		private uint _Ch3TotalPacketBitErrors;

		private uint _Ch3FirstHalfBitErrors;

		private uint _Ch3LastHalfBitErrors;

		private uint _Ch3RssiReading;

		private uint _Ch4PacketsReceived;

		private uint _Ch4PacketAccessErrorCode;

		private uint _Ch4HecErrors;

		private uint _Ch4CrcErrors;

		private uint _Ch4TotalPacketBitErrors;

		private uint _Ch4FirstHalfBitErrors;

		private uint _Ch4LastHalfBitErrors;

		private uint _Ch4RssiReading;

		private uint _Ch5PacketsReceived;

		private uint _Ch5PacketAccessErrorCode;

		private uint _Ch5HecErrors;

		private uint _Ch5CrcErrors;

		private uint _Ch5TotalPacketBitErrors;

		private uint _Ch5FirstHalfBitErrors;

		private uint _Ch5LastHalfBitErrors;

		private uint _Ch5RssiReading;

		public uint Command => 4u;

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

		public uint Ch1PacketsReceived
		{
			get
			{
				return _Ch1PacketsReceived;
			}
			set
			{
				_Ch1PacketsReceived = value;
			}
		}

		public uint Ch1PacketAccessErrorCode
		{
			get
			{
				return _Ch1PacketAccessErrorCode;
			}
			set
			{
				_Ch1PacketAccessErrorCode = value;
			}
		}

		public uint Ch1HecErrors
		{
			get
			{
				return _Ch1HecErrors;
			}
			set
			{
				_Ch1HecErrors = value;
			}
		}

		public uint Ch1CrcErrors
		{
			get
			{
				return _Ch1CrcErrors;
			}
			set
			{
				_Ch1CrcErrors = value;
			}
		}

		public uint Ch1TotalPacketBitErrors
		{
			get
			{
				return _Ch1TotalPacketBitErrors;
			}
			set
			{
				_Ch1TotalPacketBitErrors = value;
			}
		}

		public uint Ch1FirstHalfBitErrors
		{
			get
			{
				return _Ch1FirstHalfBitErrors;
			}
			set
			{
				_Ch1FirstHalfBitErrors = value;
			}
		}

		public uint Ch1LastHalfBitErrors
		{
			get
			{
				return _Ch1LastHalfBitErrors;
			}
			set
			{
				_Ch1LastHalfBitErrors = value;
			}
		}

		public uint Ch1RssiReading
		{
			get
			{
				return _Ch1RssiReading;
			}
			set
			{
				_Ch1RssiReading = value;
			}
		}

		public uint Ch2PacketsReceived
		{
			get
			{
				return _Ch2PacketsReceived;
			}
			set
			{
				_Ch2PacketsReceived = value;
			}
		}

		public uint Ch2PacketAccessErrorCode
		{
			get
			{
				return _Ch2PacketAccessErrorCode;
			}
			set
			{
				_Ch2PacketAccessErrorCode = value;
			}
		}

		public uint Ch2HecErrors
		{
			get
			{
				return _Ch2HecErrors;
			}
			set
			{
				_Ch2HecErrors = value;
			}
		}

		public uint Ch2CrcErrors
		{
			get
			{
				return _Ch2CrcErrors;
			}
			set
			{
				_Ch2CrcErrors = value;
			}
		}

		public uint Ch2TotalPacketBitErrors
		{
			get
			{
				return _Ch2TotalPacketBitErrors;
			}
			set
			{
				_Ch2TotalPacketBitErrors = value;
			}
		}

		public uint Ch2FirstHalfBitErrors
		{
			get
			{
				return _Ch2FirstHalfBitErrors;
			}
			set
			{
				_Ch2FirstHalfBitErrors = value;
			}
		}

		public uint Ch2LastHalfBitErrors
		{
			get
			{
				return _Ch2LastHalfBitErrors;
			}
			set
			{
				_Ch2LastHalfBitErrors = value;
			}
		}

		public uint Ch2RssiReading
		{
			get
			{
				return _Ch2RssiReading;
			}
			set
			{
				_Ch2RssiReading = value;
			}
		}

		public uint Ch3PacketsReceived
		{
			get
			{
				return _Ch3PacketsReceived;
			}
			set
			{
				_Ch3PacketsReceived = value;
			}
		}

		public uint Ch3PacketAccessErrorCode
		{
			get
			{
				return _Ch3PacketAccessErrorCode;
			}
			set
			{
				_Ch3PacketAccessErrorCode = value;
			}
		}

		public uint Ch3HecErrors
		{
			get
			{
				return _Ch3HecErrors;
			}
			set
			{
				_Ch3HecErrors = value;
			}
		}

		public uint Ch3CrcErrors
		{
			get
			{
				return _Ch3CrcErrors;
			}
			set
			{
				_Ch3CrcErrors = value;
			}
		}

		public uint Ch3TotalPacketBitErrors
		{
			get
			{
				return _Ch3TotalPacketBitErrors;
			}
			set
			{
				_Ch3TotalPacketBitErrors = value;
			}
		}

		public uint Ch3FirstHalfBitErrors
		{
			get
			{
				return _Ch3FirstHalfBitErrors;
			}
			set
			{
				_Ch3FirstHalfBitErrors = value;
			}
		}

		public uint Ch3LastHalfBitErrors
		{
			get
			{
				return _Ch3LastHalfBitErrors;
			}
			set
			{
				_Ch3LastHalfBitErrors = value;
			}
		}

		public uint Ch3RssiReading
		{
			get
			{
				return _Ch3RssiReading;
			}
			set
			{
				_Ch3RssiReading = value;
			}
		}

		public uint Ch4PacketsReceived
		{
			get
			{
				return _Ch4PacketsReceived;
			}
			set
			{
				_Ch4PacketsReceived = value;
			}
		}

		public uint Ch4PacketAccessErrorCode
		{
			get
			{
				return _Ch4PacketAccessErrorCode;
			}
			set
			{
				_Ch4PacketAccessErrorCode = value;
			}
		}

		public uint Ch4HecErrors
		{
			get
			{
				return _Ch4HecErrors;
			}
			set
			{
				_Ch4HecErrors = value;
			}
		}

		public uint Ch4CrcErrors
		{
			get
			{
				return _Ch4CrcErrors;
			}
			set
			{
				_Ch4CrcErrors = value;
			}
		}

		public uint Ch4TotalPacketBitErrors
		{
			get
			{
				return _Ch4TotalPacketBitErrors;
			}
			set
			{
				_Ch4TotalPacketBitErrors = value;
			}
		}

		public uint Ch4FirstHalfBitErrors
		{
			get
			{
				return _Ch4FirstHalfBitErrors;
			}
			set
			{
				_Ch4FirstHalfBitErrors = value;
			}
		}

		public uint Ch4LastHalfBitErrors
		{
			get
			{
				return _Ch4LastHalfBitErrors;
			}
			set
			{
				_Ch4LastHalfBitErrors = value;
			}
		}

		public uint Ch4RssiReading
		{
			get
			{
				return _Ch4RssiReading;
			}
			set
			{
				_Ch4RssiReading = value;
			}
		}

		public uint Ch5PacketsReceived
		{
			get
			{
				return _Ch5PacketsReceived;
			}
			set
			{
				_Ch5PacketsReceived = value;
			}
		}

		public uint Ch5PacketAccessErrorCode
		{
			get
			{
				return _Ch5PacketAccessErrorCode;
			}
			set
			{
				_Ch5PacketAccessErrorCode = value;
			}
		}

		public uint Ch5HecErrors
		{
			get
			{
				return _Ch5HecErrors;
			}
			set
			{
				_Ch5HecErrors = value;
			}
		}

		public uint Ch5CrcErrors
		{
			get
			{
				return _Ch5CrcErrors;
			}
			set
			{
				_Ch5CrcErrors = value;
			}
		}

		public uint Ch5TotalPacketBitErrors
		{
			get
			{
				return _Ch5TotalPacketBitErrors;
			}
			set
			{
				_Ch5TotalPacketBitErrors = value;
			}
		}

		public uint Ch5FirstHalfBitErrors
		{
			get
			{
				return _Ch5FirstHalfBitErrors;
			}
			set
			{
				_Ch5FirstHalfBitErrors = value;
			}
		}

		public uint Ch5LastHalfBitErrors
		{
			get
			{
				return _Ch5LastHalfBitErrors;
			}
			set
			{
				_Ch5LastHalfBitErrors = value;
			}
		}

		public uint Ch5RssiReading
		{
			get
			{
				return _Ch5RssiReading;
			}
			set
			{
				_Ch5RssiReading = value;
			}
		}
	}

	private const uint _EventCode = 255u;

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

	private PacketInfoBase info;

	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 ProdTestStatsEventInfo(this);
			}
			return info;
		}
	}

	public uint EventCode => 255u;

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

	public UserFieldsWrapper UserFields => _UserFields;

	protected override bool FromBitBuilder(ref BitBuilder bitBuilder)
	{
		if (bitBuilder.RemoveBitsAsUint(8) != EventCode)
		{
			return false;
		}
		_PayloadLength = bitBuilder.RemoveBitsAsUint(8);
		int numberOfBits = bitBuilder.GetNumberOfBits();
		if (numberOfBits > _PayloadLength * 8 + 7)
		{
			return false;
		}
		if (numberOfBits < _PayloadLength * 8)
		{
			return false;
		}
		if (bitBuilder.RemoveBitsAsUint(8) != UserFields.Command)
		{
			return false;
		}
		UserFields.ReceivedPackets = bitBuilder.RemoveBitsAsUintLittleEndian(16);
		UserFields.Ch1PacketsReceived = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch1PacketAccessErrorCode = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch1HecErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch1CrcErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch1TotalPacketBitErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch1FirstHalfBitErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch1LastHalfBitErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch1RssiReading = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch2PacketsReceived = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch2PacketAccessErrorCode = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch2HecErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch2CrcErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch2TotalPacketBitErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch2FirstHalfBitErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch2LastHalfBitErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch2RssiReading = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch3PacketsReceived = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch3PacketAccessErrorCode = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch3HecErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch3CrcErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch3TotalPacketBitErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch3FirstHalfBitErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch3LastHalfBitErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch3RssiReading = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch4PacketsReceived = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch4PacketAccessErrorCode = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch4HecErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch4CrcErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch4TotalPacketBitErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch4FirstHalfBitErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch4LastHalfBitErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch4RssiReading = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch5PacketsReceived = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch5PacketAccessErrorCode = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch5HecErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch5CrcErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch5TotalPacketBitErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch5FirstHalfBitErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch5LastHalfBitErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch5RssiReading = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		if (bitBuilder.GetNumberOfBits() > 7)
		{
			return false;
		}
		return true;
	}

	public override string ToBitString()
	{
		BitBuilder bitBuilder = new BitBuilder();
		bitBuilder.AddBitsAsUint(EventCode, 8);
		int numberOfBits = bitBuilder.GetNumberOfBits();
		bitBuilder.AddBitsAsUint(0u, 8);
		bitBuilder.AddBitsAsUint(UserFields.Command, 8);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.ReceivedPackets, 16);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch1PacketsReceived, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch1PacketAccessErrorCode, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch1HecErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch1CrcErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch1TotalPacketBitErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch1FirstHalfBitErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch1LastHalfBitErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch1RssiReading, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch2PacketsReceived, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch2PacketAccessErrorCode, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch2HecErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch2CrcErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch2TotalPacketBitErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch2FirstHalfBitErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch2LastHalfBitErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch2RssiReading, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch3PacketsReceived, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch3PacketAccessErrorCode, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch3HecErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch3CrcErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch3TotalPacketBitErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch3FirstHalfBitErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch3LastHalfBitErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch3RssiReading, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch4PacketsReceived, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch4PacketAccessErrorCode, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch4HecErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch4CrcErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch4TotalPacketBitErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch4FirstHalfBitErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch4LastHalfBitErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch4RssiReading, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch5PacketsReceived, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch5PacketAccessErrorCode, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch5HecErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch5CrcErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch5TotalPacketBitErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch5FirstHalfBitErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch5LastHalfBitErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch5RssiReading, 32);
		_PayloadLength = (uint)((bitBuilder.GetNumberOfBits() - numberOfBits - 8) / 8);
		if ((bitBuilder.GetNumberOfBits() - numberOfBits - 8) % 8 != 0)
		{
			_PayloadLength++;
		}
		bitBuilder.ChangeBitsAsUint(numberOfBits, _PayloadLength, 8);
		return bitBuilder.ToString();
	}
}
