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

namespace QCRPG.TSL.FMHCI.Packets;

public class SetHiLoInjection : PacketBase
{
	public class UserFieldsWrapper
	{
		private uint _FrequencyCount;

		private uint _Frequency0;

		private uint _InjectionSide0;

		private uint _Frequency1;

		private uint _InjectionSide1;

		private uint _Frequency2;

		private uint _InjectionSide2;

		private uint _Frequency3;

		private uint _InjectionSide3;

		private uint _Frequency4;

		private uint _InjectionSide4;

		private uint _Frequency5;

		private uint _InjectionSide5;

		private uint _Frequency6;

		private uint _InjectionSide6;

		private uint _Frequency7;

		private uint _InjectionSide7;

		private uint _Frequency8;

		private uint _InjectionSide8;

		private uint _Frequency9;

		private uint _InjectionSide9;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

		public InjectionSideEnum GetInjectionSide0AsInjectionSideEnum()
		{
			return InjectionSideInfo.ValueToInjectionSide(_InjectionSide0);
		}

		public void SetInjectionSide0AsInjectionSideEnum(InjectionSideEnum enumItem)
		{
			InjectionSide0 = InjectionSideInfo.InjectionSideToValue(enumItem);
		}

		public InjectionSideEnum GetInjectionSide1AsInjectionSideEnum()
		{
			return InjectionSideInfo.ValueToInjectionSide(_InjectionSide1);
		}

		public void SetInjectionSide1AsInjectionSideEnum(InjectionSideEnum enumItem)
		{
			InjectionSide1 = InjectionSideInfo.InjectionSideToValue(enumItem);
		}

		public InjectionSideEnum GetInjectionSide2AsInjectionSideEnum()
		{
			return InjectionSideInfo.ValueToInjectionSide(_InjectionSide2);
		}

		public void SetInjectionSide2AsInjectionSideEnum(InjectionSideEnum enumItem)
		{
			InjectionSide2 = InjectionSideInfo.InjectionSideToValue(enumItem);
		}

		public InjectionSideEnum GetInjectionSide3AsInjectionSideEnum()
		{
			return InjectionSideInfo.ValueToInjectionSide(_InjectionSide3);
		}

		public void SetInjectionSide3AsInjectionSideEnum(InjectionSideEnum enumItem)
		{
			InjectionSide3 = InjectionSideInfo.InjectionSideToValue(enumItem);
		}

		public InjectionSideEnum GetInjectionSide4AsInjectionSideEnum()
		{
			return InjectionSideInfo.ValueToInjectionSide(_InjectionSide4);
		}

		public void SetInjectionSide4AsInjectionSideEnum(InjectionSideEnum enumItem)
		{
			InjectionSide4 = InjectionSideInfo.InjectionSideToValue(enumItem);
		}

		public InjectionSideEnum GetInjectionSide5AsInjectionSideEnum()
		{
			return InjectionSideInfo.ValueToInjectionSide(_InjectionSide5);
		}

		public void SetInjectionSide5AsInjectionSideEnum(InjectionSideEnum enumItem)
		{
			InjectionSide5 = InjectionSideInfo.InjectionSideToValue(enumItem);
		}

		public InjectionSideEnum GetInjectionSide6AsInjectionSideEnum()
		{
			return InjectionSideInfo.ValueToInjectionSide(_InjectionSide6);
		}

		public void SetInjectionSide6AsInjectionSideEnum(InjectionSideEnum enumItem)
		{
			InjectionSide6 = InjectionSideInfo.InjectionSideToValue(enumItem);
		}

		public InjectionSideEnum GetInjectionSide7AsInjectionSideEnum()
		{
			return InjectionSideInfo.ValueToInjectionSide(_InjectionSide7);
		}

		public void SetInjectionSide7AsInjectionSideEnum(InjectionSideEnum enumItem)
		{
			InjectionSide7 = InjectionSideInfo.InjectionSideToValue(enumItem);
		}

		public InjectionSideEnum GetInjectionSide8AsInjectionSideEnum()
		{
			return InjectionSideInfo.ValueToInjectionSide(_InjectionSide8);
		}

		public void SetInjectionSide8AsInjectionSideEnum(InjectionSideEnum enumItem)
		{
			InjectionSide8 = InjectionSideInfo.InjectionSideToValue(enumItem);
		}

		public InjectionSideEnum GetInjectionSide9AsInjectionSideEnum()
		{
			return InjectionSideInfo.ValueToInjectionSide(_InjectionSide9);
		}

		public void SetInjectionSide9AsInjectionSideEnum(InjectionSideEnum enumItem)
		{
			InjectionSide9 = InjectionSideInfo.InjectionSideToValue(enumItem);
		}
	}

	private const uint _Opcode = 19485u;

	private Type[] expectedResponseTypes = new Type[1] { typeof(CommandCompleteForSetHiLoInjection) };

	private PacketInfoBase info;

	private uint _PayloadLength;

	public UserFieldsWrapper _UserFields = new UserFieldsWrapper();

	public override PacketType Type => PacketType.Command;

	public override Type[] ExpectedResponseTypes => expectedResponseTypes;

	public override PacketInfoBase Info
	{
		get
		{
			if (info == null)
			{
				info = new SetHiLoInjectionInfo(this);
			}
			return info;
		}
	}

	public uint Opcode => 19485u;

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

	public UserFieldsWrapper UserFields => _UserFields;

	protected override bool FromBitBuilder(ref BitBuilder bitBuilder)
	{
		if (bitBuilder.RemoveBitsAsUintLittleEndian(16) != Opcode)
		{
			return false;
		}
		_PayloadLength = bitBuilder.RemoveBitsAsUint(8);
		int numberOfBits = bitBuilder.GetNumberOfBits();
		if (numberOfBits > _PayloadLength * 8 + 7)
		{
			return false;
		}
		if (numberOfBits < _PayloadLength * 8)
		{
			return false;
		}
		UserFields.FrequencyCount = bitBuilder.RemoveBitsAsUint(8);
		UserFields.Frequency0 = bitBuilder.RemoveBitsAsUintLittleEndian(24);
		UserFields.InjectionSide0 = bitBuilder.RemoveBitsAsUint(8);
		UserFields.Frequency1 = bitBuilder.RemoveBitsAsUintLittleEndian(24);
		UserFields.InjectionSide1 = bitBuilder.RemoveBitsAsUint(8);
		UserFields.Frequency2 = bitBuilder.RemoveBitsAsUintLittleEndian(24);
		UserFields.InjectionSide2 = bitBuilder.RemoveBitsAsUint(8);
		UserFields.Frequency3 = bitBuilder.RemoveBitsAsUintLittleEndian(24);
		UserFields.InjectionSide3 = bitBuilder.RemoveBitsAsUint(8);
		UserFields.Frequency4 = bitBuilder.RemoveBitsAsUintLittleEndian(24);
		UserFields.InjectionSide4 = bitBuilder.RemoveBitsAsUint(8);
		UserFields.Frequency5 = bitBuilder.RemoveBitsAsUintLittleEndian(24);
		UserFields.InjectionSide5 = bitBuilder.RemoveBitsAsUint(8);
		UserFields.Frequency6 = bitBuilder.RemoveBitsAsUintLittleEndian(24);
		UserFields.InjectionSide6 = bitBuilder.RemoveBitsAsUint(8);
		UserFields.Frequency7 = bitBuilder.RemoveBitsAsUintLittleEndian(24);
		UserFields.InjectionSide7 = bitBuilder.RemoveBitsAsUint(8);
		UserFields.Frequency8 = bitBuilder.RemoveBitsAsUintLittleEndian(24);
		UserFields.InjectionSide8 = bitBuilder.RemoveBitsAsUint(8);
		UserFields.Frequency9 = bitBuilder.RemoveBitsAsUintLittleEndian(24);
		UserFields.InjectionSide9 = bitBuilder.RemoveBitsAsUint(8);
		if (bitBuilder.GetNumberOfBits() > 7)
		{
			return false;
		}
		return true;
	}

	public override string ToBitString()
	{
		BitBuilder bitBuilder = new BitBuilder();
		bitBuilder.AddBitsAsUintLittleEndian(Opcode, 16);
		int numberOfBits = bitBuilder.GetNumberOfBits();
		bitBuilder.AddBitsAsUint(0u, 8);
		bitBuilder.AddBitsAsUint(UserFields.FrequencyCount, 8);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Frequency0, 24);
		bitBuilder.AddBitsAsUint(UserFields.InjectionSide0, 8);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Frequency1, 24);
		bitBuilder.AddBitsAsUint(UserFields.InjectionSide1, 8);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Frequency2, 24);
		bitBuilder.AddBitsAsUint(UserFields.InjectionSide2, 8);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Frequency3, 24);
		bitBuilder.AddBitsAsUint(UserFields.InjectionSide3, 8);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Frequency4, 24);
		bitBuilder.AddBitsAsUint(UserFields.InjectionSide4, 8);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Frequency5, 24);
		bitBuilder.AddBitsAsUint(UserFields.InjectionSide5, 8);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Frequency6, 24);
		bitBuilder.AddBitsAsUint(UserFields.InjectionSide6, 8);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Frequency7, 24);
		bitBuilder.AddBitsAsUint(UserFields.InjectionSide7, 8);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Frequency8, 24);
		bitBuilder.AddBitsAsUint(UserFields.InjectionSide8, 8);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.Frequency9, 24);
		bitBuilder.AddBitsAsUint(UserFields.InjectionSide9, 8);
		_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.FrequencyCount > 10)
		{
			list.Add("Maximum allowed value for Frequency Count is 0xA");
		}
		if (UserFields.InjectionSide0 > 2)
		{
			list.Add("Maximum allowed value for Injection Side 0 is 0x2");
		}
		if (UserFields.InjectionSide1 > 2)
		{
			list.Add("Maximum allowed value for Injection Side 1 is 0x2");
		}
		if (UserFields.InjectionSide2 > 2)
		{
			list.Add("Maximum allowed value for Injection Side 2 is 0x2");
		}
		if (UserFields.InjectionSide3 > 2)
		{
			list.Add("Maximum allowed value for Injection Side 3 is 0x2");
		}
		if (UserFields.InjectionSide4 > 2)
		{
			list.Add("Maximum allowed value for Injection Side 4 is 0x2");
		}
		if (UserFields.InjectionSide5 > 2)
		{
			list.Add("Maximum allowed value for Injection Side 5 is 0x2");
		}
		if (UserFields.InjectionSide6 > 2)
		{
			list.Add("Maximum allowed value for Injection Side 6 is 0x2");
		}
		if (UserFields.InjectionSide7 > 2)
		{
			list.Add("Maximum allowed value for Injection Side 7 is 0x2");
		}
		if (UserFields.InjectionSide8 > 2)
		{
			list.Add("Maximum allowed value for Injection Side 8 is 0x2");
		}
		if (UserFields.InjectionSide9 > 2)
		{
			list.Add("Maximum allowed value for Injection Side 9 is 0x2");
		}
		return list;
	}
}
