using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class CommandCompleteForSetMwsSignaling : PacketBase
{
	public class UserFieldsWrapper
	{
		private const uint _CommandOpcode = 3184u;

		private uint _NumHciCommandPackets;

		private uint _Status;

		private uint _BluetoothRxPriorityAssertOffset;

		private uint _BluetoothRxPriorityAssertJitter;

		private uint _BluetoothRxPriorityDeassertOffset;

		private uint _Ieee802RxBluetoothRxPriorityDeassertJitter;

		private uint _PriorityAssertOffset;

		private uint _Ieee802RxPriorityAssertJitter;

		private uint _Ieee802RxPriorityDeassertOffset;

		private uint _Ieee802RxPriorityDeassertJitter;

		private uint _BluetoothTxOnAssertOffset;

		private uint _BluetoothTxOnAssertJitter;

		private uint _BluetoothTxOnDeassertOffset;

		private uint _BluetoothTxOnDeassertJitter;

		private uint _Ieee802TxOnAssertOffset;

		private uint _Ieee802TxOnAssertJitter;

		private uint _Ieee802TxOnDeassertOffset;

		private uint _Ieee802TxOnDeassertJitter;

		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 => 3184u;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

		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 CommandCompleteForSetMwsSignalingInfo(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);
		UserFields.BluetoothRxPriorityAssertOffset = bitBuilder.RemoveBitsAsUintLittleEndian(16);
		UserFields.BluetoothRxPriorityAssertJitter = bitBuilder.RemoveBitsAsUintLittleEndian(16);
		UserFields.BluetoothRxPriorityDeassertOffset = bitBuilder.RemoveBitsAsUintLittleEndian(16);
		UserFields.Ieee802RxBluetoothRxPriorityDeassertJitter = bitBuilder.RemoveBitsAsUintLittleEndian(16);
		UserFields.PriorityAssertOffset = bitBuilder.RemoveBitsAsUintLittleEndian(16);
		UserFields.Ieee802RxPriorityAssertJitter = bitBuilder.RemoveBitsAsUintLittleEndian(16);
		UserFields.Ieee802RxPriorityDeassertOffset = bitBuilder.RemoveBitsAsUintLittleEndian(16);
		UserFields.Ieee802RxPriorityDeassertJitter = bitBuilder.RemoveBitsAsUintLittleEndian(16);
		UserFields.BluetoothTxOnAssertOffset = bitBuilder.RemoveBitsAsUintLittleEndian(16);
		UserFields.BluetoothTxOnAssertJitter = bitBuilder.RemoveBitsAsUintLittleEndian(16);
		UserFields.BluetoothTxOnDeassertOffset = bitBuilder.RemoveBitsAsUintLittleEndian(16);
		UserFields.BluetoothTxOnDeassertJitter = bitBuilder.RemoveBitsAsUintLittleEndian(16);
		UserFields.Ieee802TxOnAssertOffset = bitBuilder.RemoveBitsAsUintLittleEndian(16);
		UserFields.Ieee802TxOnAssertJitter = bitBuilder.RemoveBitsAsUintLittleEndian(16);
		UserFields.Ieee802TxOnDeassertOffset = bitBuilder.RemoveBitsAsUintLittleEndian(16);
		UserFields.Ieee802TxOnDeassertJitter = bitBuilder.RemoveBitsAsUintLittleEndian(16);
		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.AddBitsAsUintLittleEndian(UserFields.BluetoothRxPriorityAssertOffset, 16);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.BluetoothRxPriorityAssertJitter, 16);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.BluetoothRxPriorityDeassertOffset, 16);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ieee802RxBluetoothRxPriorityDeassertJitter, 16);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.PriorityAssertOffset, 16);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ieee802RxPriorityAssertJitter, 16);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ieee802RxPriorityDeassertOffset, 16);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ieee802RxPriorityDeassertJitter, 16);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.BluetoothTxOnAssertOffset, 16);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.BluetoothTxOnAssertJitter, 16);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.BluetoothTxOnDeassertOffset, 16);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.BluetoothTxOnDeassertJitter, 16);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ieee802TxOnAssertOffset, 16);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ieee802TxOnAssertJitter, 16);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ieee802TxOnDeassertOffset, 16);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Ieee802TxOnDeassertJitter, 16);
		_PayloadLength = (uint)((bitBuilder.GetNumberOfBits() - numberOfBits - 8) / 8);
		if ((bitBuilder.GetNumberOfBits() - numberOfBits - 8) % 8 != 0)
		{
			_PayloadLength++;
		}
		bitBuilder.ChangeBitsAsUint(numberOfBits, _PayloadLength, 8);
		return bitBuilder.ToString();
	}
}
