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

namespace QCRPG.TSL.FMHCI.Packets;

public class CommandCompleteForChipTestDcCalibration : PacketBase
{
	public class UserFieldsWrapper
	{
		private const uint _CommandOpcode = 23560u;

		private uint _NumHciCommandPackets;

		private uint _Status;

		private uint _DccLoI0;

		private uint _DccLoI1;

		private uint _DccLoI2;

		private uint _DccLoI3;

		private uint _DccLoQ0;

		private uint _DccLoQ1;

		private uint _DccLoQ2;

		private uint _DccLoQ3;

		private uint _DccHiI0;

		private uint _DccHiI1;

		private uint _DccHiI2;

		private uint _DccHiI3;

		private uint _DccHiQ0;

		private uint _DccHiQ1;

		private uint _DccHiQ2;

		private uint _DccHiQ3;

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

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

		public uint DccLoI0
		{
			get
			{
				return _DccLoI0;
			}
			set
			{
				if (value > 16777215)
				{
					throw new Exception("Maximum possible value for DccLoI0 is 0xFFFFFF");
				}
				_DccLoI0 = value;
			}
		}

		public uint DccLoI1
		{
			get
			{
				return _DccLoI1;
			}
			set
			{
				if (value > 16777215)
				{
					throw new Exception("Maximum possible value for DccLoI1 is 0xFFFFFF");
				}
				_DccLoI1 = value;
			}
		}

		public uint DccLoI2
		{
			get
			{
				return _DccLoI2;
			}
			set
			{
				if (value > 16777215)
				{
					throw new Exception("Maximum possible value for DccLoI2 is 0xFFFFFF");
				}
				_DccLoI2 = value;
			}
		}

		public uint DccLoI3
		{
			get
			{
				return _DccLoI3;
			}
			set
			{
				if (value > 16777215)
				{
					throw new Exception("Maximum possible value for DccLoI3 is 0xFFFFFF");
				}
				_DccLoI3 = value;
			}
		}

		public uint DccLoQ0
		{
			get
			{
				return _DccLoQ0;
			}
			set
			{
				if (value > 16777215)
				{
					throw new Exception("Maximum possible value for DccLoQ0 is 0xFFFFFF");
				}
				_DccLoQ0 = value;
			}
		}

		public uint DccLoQ1
		{
			get
			{
				return _DccLoQ1;
			}
			set
			{
				if (value > 16777215)
				{
					throw new Exception("Maximum possible value for DccLoQ1 is 0xFFFFFF");
				}
				_DccLoQ1 = value;
			}
		}

		public uint DccLoQ2
		{
			get
			{
				return _DccLoQ2;
			}
			set
			{
				if (value > 16777215)
				{
					throw new Exception("Maximum possible value for DccLoQ2 is 0xFFFFFF");
				}
				_DccLoQ2 = value;
			}
		}

		public uint DccLoQ3
		{
			get
			{
				return _DccLoQ3;
			}
			set
			{
				if (value > 16777215)
				{
					throw new Exception("Maximum possible value for DccLoQ3 is 0xFFFFFF");
				}
				_DccLoQ3 = value;
			}
		}

		public uint DccHiI0
		{
			get
			{
				return _DccHiI0;
			}
			set
			{
				if (value > 16777215)
				{
					throw new Exception("Maximum possible value for DccHiI0 is 0xFFFFFF");
				}
				_DccHiI0 = value;
			}
		}

		public uint DccHiI1
		{
			get
			{
				return _DccHiI1;
			}
			set
			{
				if (value > 16777215)
				{
					throw new Exception("Maximum possible value for DccHiI1 is 0xFFFFFF");
				}
				_DccHiI1 = value;
			}
		}

		public uint DccHiI2
		{
			get
			{
				return _DccHiI2;
			}
			set
			{
				if (value > 16777215)
				{
					throw new Exception("Maximum possible value for DccHiI2 is 0xFFFFFF");
				}
				_DccHiI2 = value;
			}
		}

		public uint DccHiI3
		{
			get
			{
				return _DccHiI3;
			}
			set
			{
				if (value > 16777215)
				{
					throw new Exception("Maximum possible value for DccHiI3 is 0xFFFFFF");
				}
				_DccHiI3 = value;
			}
		}

		public uint DccHiQ0
		{
			get
			{
				return _DccHiQ0;
			}
			set
			{
				if (value > 16777215)
				{
					throw new Exception("Maximum possible value for DccHiQ0 is 0xFFFFFF");
				}
				_DccHiQ0 = value;
			}
		}

		public uint DccHiQ1
		{
			get
			{
				return _DccHiQ1;
			}
			set
			{
				if (value > 16777215)
				{
					throw new Exception("Maximum possible value for DccHiQ1 is 0xFFFFFF");
				}
				_DccHiQ1 = value;
			}
		}

		public uint DccHiQ2
		{
			get
			{
				return _DccHiQ2;
			}
			set
			{
				if (value > 16777215)
				{
					throw new Exception("Maximum possible value for DccHiQ2 is 0xFFFFFF");
				}
				_DccHiQ2 = value;
			}
		}

		public uint DccHiQ3
		{
			get
			{
				return _DccHiQ3;
			}
			set
			{
				if (value > 16777215)
				{
					throw new Exception("Maximum possible value for DccHiQ3 is 0xFFFFFF");
				}
				_DccHiQ3 = value;
			}
		}

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

		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 CommandCompleteForChipTestDcCalibrationInfo(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);
		UserFields.DccLoI0 = bitBuilder.RemoveBitsAsUintLittleEndian(24);
		UserFields.DccLoI1 = bitBuilder.RemoveBitsAsUintLittleEndian(24);
		UserFields.DccLoI2 = bitBuilder.RemoveBitsAsUintLittleEndian(24);
		UserFields.DccLoI3 = bitBuilder.RemoveBitsAsUintLittleEndian(24);
		UserFields.DccLoQ0 = bitBuilder.RemoveBitsAsUintLittleEndian(24);
		UserFields.DccLoQ1 = bitBuilder.RemoveBitsAsUintLittleEndian(24);
		UserFields.DccLoQ2 = bitBuilder.RemoveBitsAsUintLittleEndian(24);
		UserFields.DccLoQ3 = bitBuilder.RemoveBitsAsUintLittleEndian(24);
		UserFields.DccHiI0 = bitBuilder.RemoveBitsAsUintLittleEndian(24);
		UserFields.DccHiI1 = bitBuilder.RemoveBitsAsUintLittleEndian(24);
		UserFields.DccHiI2 = bitBuilder.RemoveBitsAsUintLittleEndian(24);
		UserFields.DccHiI3 = bitBuilder.RemoveBitsAsUintLittleEndian(24);
		UserFields.DccHiQ0 = bitBuilder.RemoveBitsAsUintLittleEndian(24);
		UserFields.DccHiQ1 = bitBuilder.RemoveBitsAsUintLittleEndian(24);
		UserFields.DccHiQ2 = bitBuilder.RemoveBitsAsUintLittleEndian(24);
		UserFields.DccHiQ3 = bitBuilder.RemoveBitsAsUintLittleEndian(24);
		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.DccLoI0, 24);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.DccLoI1, 24);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.DccLoI2, 24);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.DccLoI3, 24);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.DccLoQ0, 24);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.DccLoQ1, 24);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.DccLoQ2, 24);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.DccLoQ3, 24);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.DccHiI0, 24);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.DccHiI1, 24);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.DccHiI2, 24);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.DccHiI3, 24);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.DccHiQ0, 24);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.DccHiQ1, 24);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.DccHiQ2, 24);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.DccHiQ3, 24);
		_PayloadLength = (uint)((bitBuilder.GetNumberOfBits() - numberOfBits - 8) / 8);
		if ((bitBuilder.GetNumberOfBits() - numberOfBits - 8) % 8 != 0)
		{
			_PayloadLength++;
		}
		bitBuilder.ChangeBitsAsUint(numberOfBits, _PayloadLength, 8);
		return bitBuilder.ToString();
	}

	public override List<string> GetWarnings()
	{
		List<string> list = new List<string>();
		if (UserFields.DccLoI0 > 4194303)
		{
			list.Add("Maximum allowed value for DCC_LO_I 0 is 0x3FFFFF");
		}
		if (UserFields.DccLoI1 > 4194303)
		{
			list.Add("Maximum allowed value for DCC_LO_I 1 is 0x3FFFFF");
		}
		if (UserFields.DccLoI2 > 4194303)
		{
			list.Add("Maximum allowed value for DCC_LO_I 2 is 0x3FFFFF");
		}
		if (UserFields.DccLoI3 > 4194303)
		{
			list.Add("Maximum allowed value for DCC_LO_I 3 is 0x3FFFFF");
		}
		if (UserFields.DccLoQ0 > 4194303)
		{
			list.Add("Maximum allowed value for DCC_LO_Q 0 is 0x3FFFFF");
		}
		if (UserFields.DccLoQ1 > 4194303)
		{
			list.Add("Maximum allowed value for DCC_LO_Q 1 is 0x3FFFFF");
		}
		if (UserFields.DccLoQ2 > 4194303)
		{
			list.Add("Maximum allowed value for DCC_LO_Q 2 is 0x3FFFFF");
		}
		if (UserFields.DccLoQ3 > 4194303)
		{
			list.Add("Maximum allowed value for DCC_LO_Q 3 is 0x3FFFFF");
		}
		if (UserFields.DccHiI0 > 4194303)
		{
			list.Add("Maximum allowed value for DCC_HI_I 0 is 0x3FFFFF");
		}
		if (UserFields.DccHiI1 > 4194303)
		{
			list.Add("Maximum allowed value for DCC_HI_I 1 is 0x3FFFFF");
		}
		if (UserFields.DccHiI2 > 4194303)
		{
			list.Add("Maximum allowed value for DCC_HI_I 2 is 0x3FFFFF");
		}
		if (UserFields.DccHiI3 > 4194303)
		{
			list.Add("Maximum allowed value for DCC_HI_I 3 is 0x3FFFFF");
		}
		if (UserFields.DccHiQ0 > 4194303)
		{
			list.Add("Maximum allowed value for DCC_HI_Q 0 is 0x3FFFFF");
		}
		if (UserFields.DccHiQ1 > 4194303)
		{
			list.Add("Maximum allowed value for DCC_HI_Q 1 is 0x3FFFFF");
		}
		if (UserFields.DccHiQ2 > 4194303)
		{
			list.Add("Maximum allowed value for DCC_HI_Q 2 is 0x3FFFFF");
		}
		if (UserFields.DccHiQ3 > 4194303)
		{
			list.Add("Maximum allowed value for DCC_HI_Q 3 is 0x3FFFFF");
		}
		return list;
	}
}
