using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FMHCI.Packets;

public class CommandCompleteForDoProcessCalibration : PacketBase
{
	public class UserFieldsWrapper
	{
		private const uint _CommandOpcode = 21510u;

		private const uint _Mode = 1u;

		private uint _NumHciCommandPackets;

		private uint _Status;

		private uint _RcMom1;

		private uint _RcMom2;

		private uint _RcMosVar;

		private uint _RcMosCap;

		private uint _BbfCTuneG0;

		private uint _BbfCTuneG1;

		private uint _BbfCTuneG2;

		private uint _BbfCTuneG3;

		private uint _AdcCTune;

		private uint _NotchR;

		private uint _NotchC;

		private uint _PllC1Rx;

		private uint _PllC1Tx;

		private uint _PllC2Rx;

		private uint _PllC2Tx;

		private uint _PllC3Rx;

		private uint _PllC3Tx;

		private uint _PllR1Rx;

		private uint _PllR1Tx;

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

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

		public uint Mode => 1u;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	private const uint _EventCode = 15u;

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

	private PacketInfoBase info;

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

	public uint EventCode => 15u;

	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.Mode)
		{
			return false;
		}
		UserFields.RcMom1 = bitBuilder.RemoveBitsAsUintLittleEndian(16);
		UserFields.RcMom2 = bitBuilder.RemoveBitsAsUintLittleEndian(16);
		UserFields.RcMosVar = bitBuilder.RemoveBitsAsUintLittleEndian(16);
		UserFields.RcMosCap = bitBuilder.RemoveBitsAsUintLittleEndian(16);
		UserFields.BbfCTuneG0 = bitBuilder.RemoveBitsAsUint(8);
		UserFields.BbfCTuneG1 = bitBuilder.RemoveBitsAsUint(8);
		UserFields.BbfCTuneG2 = bitBuilder.RemoveBitsAsUint(8);
		UserFields.BbfCTuneG3 = bitBuilder.RemoveBitsAsUint(8);
		UserFields.AdcCTune = bitBuilder.RemoveBitsAsUint(8);
		UserFields.NotchR = bitBuilder.RemoveBitsAsUint(8);
		UserFields.NotchC = bitBuilder.RemoveBitsAsUint(8);
		UserFields.PllC1Rx = bitBuilder.RemoveBitsAsUint(8);
		UserFields.PllC1Tx = bitBuilder.RemoveBitsAsUint(8);
		UserFields.PllC2Rx = bitBuilder.RemoveBitsAsUint(8);
		UserFields.PllC2Tx = bitBuilder.RemoveBitsAsUint(8);
		UserFields.PllC3Rx = bitBuilder.RemoveBitsAsUint(8);
		UserFields.PllC3Tx = bitBuilder.RemoveBitsAsUint(8);
		UserFields.PllR1Rx = bitBuilder.RemoveBitsAsUint(8);
		UserFields.PllR1Tx = bitBuilder.RemoveBitsAsUint(8);
		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.Mode, 8);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.RcMom1, 16);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.RcMom2, 16);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.RcMosVar, 16);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.RcMosCap, 16);
		bitBuilder.AddBitsAsUint(UserFields.BbfCTuneG0, 8);
		bitBuilder.AddBitsAsUint(UserFields.BbfCTuneG1, 8);
		bitBuilder.AddBitsAsUint(UserFields.BbfCTuneG2, 8);
		bitBuilder.AddBitsAsUint(UserFields.BbfCTuneG3, 8);
		bitBuilder.AddBitsAsUint(UserFields.AdcCTune, 8);
		bitBuilder.AddBitsAsUint(UserFields.NotchR, 8);
		bitBuilder.AddBitsAsUint(UserFields.NotchC, 8);
		bitBuilder.AddBitsAsUint(UserFields.PllC1Rx, 8);
		bitBuilder.AddBitsAsUint(UserFields.PllC1Tx, 8);
		bitBuilder.AddBitsAsUint(UserFields.PllC2Rx, 8);
		bitBuilder.AddBitsAsUint(UserFields.PllC2Tx, 8);
		bitBuilder.AddBitsAsUint(UserFields.PllC3Rx, 8);
		bitBuilder.AddBitsAsUint(UserFields.PllC3Tx, 8);
		bitBuilder.AddBitsAsUint(UserFields.PllR1Rx, 8);
		bitBuilder.AddBitsAsUint(UserFields.PllR1Tx, 8);
		_PayloadLength = (uint)((bitBuilder.GetNumberOfBits() - numberOfBits - 8) / 8);
		if ((bitBuilder.GetNumberOfBits() - numberOfBits - 8) % 8 != 0)
		{
			_PayloadLength++;
		}
		bitBuilder.ChangeBitsAsUint(numberOfBits, _PayloadLength, 8);
		return bitBuilder.ToString();
	}
}
