using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class CommandCompleteForProdTestStats : PacketBase
{
	public class UserFieldsWrapper
	{
		private const uint _CommandOpcode = 64516u;

		private const uint _Command = 2u;

		private uint _NumHciCommandPackets;

		private uint _Status;

		private uint _ReceivedPackets;

		private uint _Ch1PacketsReceived;

		private uint _Ch1PacketAccessErrorCode;

		private uint _Ch1HecErrors;

		private uint _Ch1CrcErrors;

		private uint _Ch1TotalCommandcompletepacketBitErrors;

		private uint _Ch1FirstHalfBitErrors;

		private uint _Ch1LastHalfBitErrors;

		private uint _Ch1RssiReading;

		private uint _Ch2CommandcompletepacketsReceived;

		private uint _Ch2CommandcompletepacketAccessErrorCode;

		private uint _Ch2HecErrors;

		private uint _Ch2CrcErrors;

		private uint _Ch2TotalCommandcompletepacketBitErrors;

		private uint _Ch2FirstHalfBitErrors;

		private uint _Ch2LastHalfBitErrors;

		private uint _Ch2RssiReading;

		private uint _Ch3CommandcompletepacketsReceived;

		private uint _Ch3CommandcompletepacketAccessErrorCode;

		private uint _Ch3HecErrors;

		private uint _Ch3CrcErrors;

		private uint _Ch3TotalCommandcompletepacketBitErrors;

		private uint _Ch3FirstHalfBitErrors;

		private uint _Ch3LastHalfBitErrors;

		private uint _Ch3RssiReading;

		private uint _Ch4CommandcompletepacketsReceived;

		private uint _Ch4CommandcompletepacketAccessErrorCode;

		private uint _Ch4HecErrors;

		private uint _Ch4CrcErrors;

		private uint _Ch4TotalCommandcompletepacketBitErrors;

		private uint _Ch4FirstHalfBitErrors;

		private uint _Ch4LastHalfBitErrors;

		private uint _Ch4RssiReading;

		private uint _Ch5CommandcompletepacketsReceived;

		private uint _Ch5CommandcompletepacketAccessErrorCode;

		private uint _Ch5HecErrors;

		private uint _Ch5CrcErrors;

		private uint _Ch5TotalCommandcompletepacketBitErrors;

		private uint _Ch5FirstHalfBitErrors;

		private uint _Ch5LastHalfBitErrors;

		private uint _Ch5RssiReading;

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

		public uint CommandOpcode => 64516u;

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

		public uint Command => 2u;

		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 Ch1TotalCommandcompletepacketBitErrors
		{
			get
			{
				return _Ch1TotalCommandcompletepacketBitErrors;
			}
			set
			{
				_Ch1TotalCommandcompletepacketBitErrors = 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 Ch2CommandcompletepacketsReceived
		{
			get
			{
				return _Ch2CommandcompletepacketsReceived;
			}
			set
			{
				_Ch2CommandcompletepacketsReceived = value;
			}
		}

		public uint Ch2CommandcompletepacketAccessErrorCode
		{
			get
			{
				return _Ch2CommandcompletepacketAccessErrorCode;
			}
			set
			{
				_Ch2CommandcompletepacketAccessErrorCode = value;
			}
		}

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

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

		public uint Ch2TotalCommandcompletepacketBitErrors
		{
			get
			{
				return _Ch2TotalCommandcompletepacketBitErrors;
			}
			set
			{
				_Ch2TotalCommandcompletepacketBitErrors = 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 Ch3CommandcompletepacketsReceived
		{
			get
			{
				return _Ch3CommandcompletepacketsReceived;
			}
			set
			{
				_Ch3CommandcompletepacketsReceived = value;
			}
		}

		public uint Ch3CommandcompletepacketAccessErrorCode
		{
			get
			{
				return _Ch3CommandcompletepacketAccessErrorCode;
			}
			set
			{
				_Ch3CommandcompletepacketAccessErrorCode = value;
			}
		}

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

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

		public uint Ch3TotalCommandcompletepacketBitErrors
		{
			get
			{
				return _Ch3TotalCommandcompletepacketBitErrors;
			}
			set
			{
				_Ch3TotalCommandcompletepacketBitErrors = 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 Ch4CommandcompletepacketsReceived
		{
			get
			{
				return _Ch4CommandcompletepacketsReceived;
			}
			set
			{
				_Ch4CommandcompletepacketsReceived = value;
			}
		}

		public uint Ch4CommandcompletepacketAccessErrorCode
		{
			get
			{
				return _Ch4CommandcompletepacketAccessErrorCode;
			}
			set
			{
				_Ch4CommandcompletepacketAccessErrorCode = value;
			}
		}

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

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

		public uint Ch4TotalCommandcompletepacketBitErrors
		{
			get
			{
				return _Ch4TotalCommandcompletepacketBitErrors;
			}
			set
			{
				_Ch4TotalCommandcompletepacketBitErrors = 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 Ch5CommandcompletepacketsReceived
		{
			get
			{
				return _Ch5CommandcompletepacketsReceived;
			}
			set
			{
				_Ch5CommandcompletepacketsReceived = value;
			}
		}

		public uint Ch5CommandcompletepacketAccessErrorCode
		{
			get
			{
				return _Ch5CommandcompletepacketAccessErrorCode;
			}
			set
			{
				_Ch5CommandcompletepacketAccessErrorCode = value;
			}
		}

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

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

		public uint Ch5TotalCommandcompletepacketBitErrors
		{
			get
			{
				return _Ch5TotalCommandcompletepacketBitErrors;
			}
			set
			{
				_Ch5TotalCommandcompletepacketBitErrors = 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;
			}
		}

		public CommandOpcodeEnum GetCommandOpcodeAsCommandOpcodeEnum()
		{
			return CommandOpcodeInfo.ValueToCommandOpcode(64516u);
		}

		public ErrorCodeEnum GetStatusAsErrorCodeEnum()
		{
			return ErrorCodeInfo.ValueToErrorCode(_Status);
		}

		public void SetStatusAsErrorCodeEnum(ErrorCodeEnum enumItem)
		{
			Status = ErrorCodeInfo.ErrorCodeToValue(enumItem);
		}
	}

	private const uint _EventCode = 14u;

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

	public uint EventCode => 14u;

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

	public UserFieldsWrapper UserFields => _UserFields;

	public override void SetDefaultValues()
	{
		UserFields.NumHciCommandPackets = 1u;
	}

	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;
		}
		UserFields.NumHciCommandPackets = bitBuilder.RemoveBitsAsUint(8);
		if (bitBuilder.RemoveBitsAsUintLittleEndian(16) != UserFields.CommandOpcode)
		{
			return false;
		}
		UserFields.Status = bitBuilder.RemoveBitsAsUint(8);
		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.Ch1TotalCommandcompletepacketBitErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch1FirstHalfBitErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch1LastHalfBitErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch1RssiReading = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch2CommandcompletepacketsReceived = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch2CommandcompletepacketAccessErrorCode = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch2HecErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch2CrcErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch2TotalCommandcompletepacketBitErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch2FirstHalfBitErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch2LastHalfBitErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch2RssiReading = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch3CommandcompletepacketsReceived = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch3CommandcompletepacketAccessErrorCode = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch3HecErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch3CrcErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch3TotalCommandcompletepacketBitErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch3FirstHalfBitErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch3LastHalfBitErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch3RssiReading = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch4CommandcompletepacketsReceived = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch4CommandcompletepacketAccessErrorCode = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch4HecErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch4CrcErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch4TotalCommandcompletepacketBitErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch4FirstHalfBitErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch4LastHalfBitErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch4RssiReading = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch5CommandcompletepacketsReceived = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch5CommandcompletepacketAccessErrorCode = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch5HecErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch5CrcErrors = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.Ch5TotalCommandcompletepacketBitErrors = 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.NumHciCommandPackets, 8);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.CommandOpcode, 16);
		bitBuilder.AddBitsAsUint(UserFields.Status, 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.Ch1TotalCommandcompletepacketBitErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch1FirstHalfBitErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch1LastHalfBitErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch1RssiReading, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch2CommandcompletepacketsReceived, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch2CommandcompletepacketAccessErrorCode, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch2HecErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch2CrcErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch2TotalCommandcompletepacketBitErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch2FirstHalfBitErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch2LastHalfBitErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch2RssiReading, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch3CommandcompletepacketsReceived, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch3CommandcompletepacketAccessErrorCode, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch3HecErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch3CrcErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch3TotalCommandcompletepacketBitErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch3FirstHalfBitErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch3LastHalfBitErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch3RssiReading, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch4CommandcompletepacketsReceived, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch4CommandcompletepacketAccessErrorCode, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch4HecErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch4CrcErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch4TotalCommandcompletepacketBitErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch4FirstHalfBitErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch4LastHalfBitErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch4RssiReading, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch5CommandcompletepacketsReceived, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch5CommandcompletepacketAccessErrorCode, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch5HecErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch5CrcErrors, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ch5TotalCommandcompletepacketBitErrors, 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();
	}
}
