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

namespace QCRPG.TSL.FMHCI.Packets;

public class CommandCompleteForSetGetResetAgc : PacketBase
{
	public class UserFieldsWrapper
	{
		public enum UccurrentgainstateEnum
		{
			G0_HIGH,
			G1_MIDPLUS,
			G2_MID,
			G3_MIDMIN,
			G4_LOW,
			AGC_FREERUN,
			InvalidUccurrentgainstateValue
		}

		public static class UccurrentgainstateInfo
		{
			public static UccurrentgainstateEnum ValueToUccurrentgainstate(uint value)
			{
				return value switch
				{
					0u => UccurrentgainstateEnum.G0_HIGH, 
					1u => UccurrentgainstateEnum.G1_MIDPLUS, 
					2u => UccurrentgainstateEnum.G2_MID, 
					3u => UccurrentgainstateEnum.G3_MIDMIN, 
					4u => UccurrentgainstateEnum.G4_LOW, 
					5u => UccurrentgainstateEnum.AGC_FREERUN, 
					_ => UccurrentgainstateEnum.InvalidUccurrentgainstateValue, 
				};
			}

			public static uint UccurrentgainstateToValue(UccurrentgainstateEnum enumItem)
			{
				return enumItem switch
				{
					UccurrentgainstateEnum.G0_HIGH => 0u, 
					UccurrentgainstateEnum.G1_MIDPLUS => 1u, 
					UccurrentgainstateEnum.G2_MID => 2u, 
					UccurrentgainstateEnum.G3_MIDMIN => 3u, 
					UccurrentgainstateEnum.G4_LOW => 4u, 
					UccurrentgainstateEnum.AGC_FREERUN => 5u, 
					_ => uint.MaxValue, 
				};
			}

			public static string UccurrentgainstateToString(UccurrentgainstateEnum enumItem)
			{
				return enumItem switch
				{
					UccurrentgainstateEnum.G0_HIGH => "G0 state (HIGH)", 
					UccurrentgainstateEnum.G1_MIDPLUS => "G1 state (MIDPLUS)", 
					UccurrentgainstateEnum.G2_MID => "G2 state (MID)", 
					UccurrentgainstateEnum.G3_MIDMIN => "G3 state (MIDMIN)", 
					UccurrentgainstateEnum.G4_LOW => "G4 state (LOW)", 
					UccurrentgainstateEnum.AGC_FREERUN => "AGC Free Run", 
					_ => "Invalid Uccurrentgainstate Value", 
				};
			}

			public static string UccurrentgainstateToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("0x0 = G0 state (HIGH)");
				stringBuilder.AppendLine("0x1 = G1 state (MIDPLUS)");
				stringBuilder.AppendLine("0x2 = G2 state (MID)");
				stringBuilder.AppendLine("0x3 = G3 state (MIDMIN)");
				stringBuilder.AppendLine("0x4 = G4 state (LOW)");
				stringBuilder.AppendLine("0x5 = AGC Free Run");
				return stringBuilder.ToString();
			}
		}

		public enum Ucgainstatechange1Enum
		{
			G0_HIGH,
			G1_MIDPLUS,
			G2_MID,
			G3_MIDMIN,
			G4_LOW,
			AGC_FREERUN,
			InvalidUcgainstatechange1Value
		}

		public static class Ucgainstatechange1Info
		{
			public static Ucgainstatechange1Enum ValueToUcgainstatechange1(uint value)
			{
				return value switch
				{
					0u => Ucgainstatechange1Enum.G0_HIGH, 
					1u => Ucgainstatechange1Enum.G1_MIDPLUS, 
					2u => Ucgainstatechange1Enum.G2_MID, 
					3u => Ucgainstatechange1Enum.G3_MIDMIN, 
					4u => Ucgainstatechange1Enum.G4_LOW, 
					5u => Ucgainstatechange1Enum.AGC_FREERUN, 
					_ => Ucgainstatechange1Enum.InvalidUcgainstatechange1Value, 
				};
			}

			public static uint Ucgainstatechange1ToValue(Ucgainstatechange1Enum enumItem)
			{
				return enumItem switch
				{
					Ucgainstatechange1Enum.G0_HIGH => 0u, 
					Ucgainstatechange1Enum.G1_MIDPLUS => 1u, 
					Ucgainstatechange1Enum.G2_MID => 2u, 
					Ucgainstatechange1Enum.G3_MIDMIN => 3u, 
					Ucgainstatechange1Enum.G4_LOW => 4u, 
					Ucgainstatechange1Enum.AGC_FREERUN => 5u, 
					_ => uint.MaxValue, 
				};
			}

			public static string Ucgainstatechange1ToString(Ucgainstatechange1Enum enumItem)
			{
				return enumItem switch
				{
					Ucgainstatechange1Enum.G0_HIGH => "G0 state (HIGH)", 
					Ucgainstatechange1Enum.G1_MIDPLUS => "G1 state (MIDPLUS)", 
					Ucgainstatechange1Enum.G2_MID => "G2 state (MID)", 
					Ucgainstatechange1Enum.G3_MIDMIN => "G3 state (MIDMIN)", 
					Ucgainstatechange1Enum.G4_LOW => "G4 state (LOW)", 
					Ucgainstatechange1Enum.AGC_FREERUN => "AGC Free Run", 
					_ => "Invalid Ucgainstatechange1 Value", 
				};
			}

			public static string Ucgainstatechange1ToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("0x0 = G0 state (HIGH)");
				stringBuilder.AppendLine("0x1 = G1 state (MIDPLUS)");
				stringBuilder.AppendLine("0x2 = G2 state (MID)");
				stringBuilder.AppendLine("0x3 = G3 state (MIDMIN)");
				stringBuilder.AppendLine("0x4 = G4 state (LOW)");
				stringBuilder.AppendLine("0x5 = AGC Free Run");
				return stringBuilder.ToString();
			}
		}

		public enum Ucgainstatechange2Enum
		{
			G0_HIGH,
			G1_MIDPLUS,
			G2_MID,
			G3_MIDMIN,
			G4_LOW,
			AGC_FREERUN,
			InvalidUcgainstatechange2Value
		}

		public static class Ucgainstatechange2Info
		{
			public static Ucgainstatechange2Enum ValueToUcgainstatechange2(uint value)
			{
				return value switch
				{
					0u => Ucgainstatechange2Enum.G0_HIGH, 
					1u => Ucgainstatechange2Enum.G1_MIDPLUS, 
					2u => Ucgainstatechange2Enum.G2_MID, 
					3u => Ucgainstatechange2Enum.G3_MIDMIN, 
					4u => Ucgainstatechange2Enum.G4_LOW, 
					5u => Ucgainstatechange2Enum.AGC_FREERUN, 
					_ => Ucgainstatechange2Enum.InvalidUcgainstatechange2Value, 
				};
			}

			public static uint Ucgainstatechange2ToValue(Ucgainstatechange2Enum enumItem)
			{
				return enumItem switch
				{
					Ucgainstatechange2Enum.G0_HIGH => 0u, 
					Ucgainstatechange2Enum.G1_MIDPLUS => 1u, 
					Ucgainstatechange2Enum.G2_MID => 2u, 
					Ucgainstatechange2Enum.G3_MIDMIN => 3u, 
					Ucgainstatechange2Enum.G4_LOW => 4u, 
					Ucgainstatechange2Enum.AGC_FREERUN => 5u, 
					_ => uint.MaxValue, 
				};
			}

			public static string Ucgainstatechange2ToString(Ucgainstatechange2Enum enumItem)
			{
				return enumItem switch
				{
					Ucgainstatechange2Enum.G0_HIGH => "G0 state (HIGH)", 
					Ucgainstatechange2Enum.G1_MIDPLUS => "G1 state (MIDPLUS)", 
					Ucgainstatechange2Enum.G2_MID => "G2 state (MID)", 
					Ucgainstatechange2Enum.G3_MIDMIN => "G3 state (MIDMIN)", 
					Ucgainstatechange2Enum.G4_LOW => "G4 state (LOW)", 
					Ucgainstatechange2Enum.AGC_FREERUN => "AGC Free Run", 
					_ => "Invalid Ucgainstatechange2 Value", 
				};
			}

			public static string Ucgainstatechange2ToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("0x0 = G0 state (HIGH)");
				stringBuilder.AppendLine("0x1 = G1 state (MIDPLUS)");
				stringBuilder.AppendLine("0x2 = G2 state (MID)");
				stringBuilder.AppendLine("0x3 = G3 state (MIDMIN)");
				stringBuilder.AppendLine("0x4 = G4 state (LOW)");
				stringBuilder.AppendLine("0x5 = AGC Free Run");
				return stringBuilder.ToString();
			}
		}

		public enum Ucgainstatechange3Enum
		{
			G0_HIGH,
			G1_MIDPLUS,
			G2_MID,
			G3_MIDMIN,
			G4_LOW,
			AGC_FREERUN,
			InvalidUcgainstatechange3Value
		}

		public static class Ucgainstatechange3Info
		{
			public static Ucgainstatechange3Enum ValueToUcgainstatechange3(uint value)
			{
				return value switch
				{
					0u => Ucgainstatechange3Enum.G0_HIGH, 
					1u => Ucgainstatechange3Enum.G1_MIDPLUS, 
					2u => Ucgainstatechange3Enum.G2_MID, 
					3u => Ucgainstatechange3Enum.G3_MIDMIN, 
					4u => Ucgainstatechange3Enum.G4_LOW, 
					5u => Ucgainstatechange3Enum.AGC_FREERUN, 
					_ => Ucgainstatechange3Enum.InvalidUcgainstatechange3Value, 
				};
			}

			public static uint Ucgainstatechange3ToValue(Ucgainstatechange3Enum enumItem)
			{
				return enumItem switch
				{
					Ucgainstatechange3Enum.G0_HIGH => 0u, 
					Ucgainstatechange3Enum.G1_MIDPLUS => 1u, 
					Ucgainstatechange3Enum.G2_MID => 2u, 
					Ucgainstatechange3Enum.G3_MIDMIN => 3u, 
					Ucgainstatechange3Enum.G4_LOW => 4u, 
					Ucgainstatechange3Enum.AGC_FREERUN => 5u, 
					_ => uint.MaxValue, 
				};
			}

			public static string Ucgainstatechange3ToString(Ucgainstatechange3Enum enumItem)
			{
				return enumItem switch
				{
					Ucgainstatechange3Enum.G0_HIGH => "G0 state (HIGH)", 
					Ucgainstatechange3Enum.G1_MIDPLUS => "G1 state (MIDPLUS)", 
					Ucgainstatechange3Enum.G2_MID => "G2 state (MID)", 
					Ucgainstatechange3Enum.G3_MIDMIN => "G3 state (MIDMIN)", 
					Ucgainstatechange3Enum.G4_LOW => "G4 state (LOW)", 
					Ucgainstatechange3Enum.AGC_FREERUN => "AGC Free Run", 
					_ => "Invalid Ucgainstatechange3 Value", 
				};
			}

			public static string Ucgainstatechange3ToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("0x0 = G0 state (HIGH)");
				stringBuilder.AppendLine("0x1 = G1 state (MIDPLUS)");
				stringBuilder.AppendLine("0x2 = G2 state (MID)");
				stringBuilder.AppendLine("0x3 = G3 state (MIDMIN)");
				stringBuilder.AppendLine("0x4 = G4 state (LOW)");
				stringBuilder.AppendLine("0x5 = AGC Free Run");
				return stringBuilder.ToString();
			}
		}

		private const uint _CommandOpcode = 64525u;

		private uint _NumHciCommandPackets;

		private uint _Status;

		private uint _Uccurrentgainstate;

		private uint _Ucgainstatechange1;

		private uint _Ucgainstatechange2;

		private uint _Ucgainstatechange3;

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

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

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

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

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

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

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

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

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

		public UccurrentgainstateEnum GetUccurrentgainstateAsUccurrentgainstateEnum()
		{
			return UccurrentgainstateInfo.ValueToUccurrentgainstate(_Uccurrentgainstate);
		}

		public void SetUccurrentgainstateAsUccurrentgainstateEnum(UccurrentgainstateEnum enumItem)
		{
			Uccurrentgainstate = UccurrentgainstateInfo.UccurrentgainstateToValue(enumItem);
		}

		public Ucgainstatechange1Enum GetUcgainstatechange1AsUcgainstatechange1Enum()
		{
			return Ucgainstatechange1Info.ValueToUcgainstatechange1(_Ucgainstatechange1);
		}

		public void SetUcgainstatechange1AsUcgainstatechange1Enum(Ucgainstatechange1Enum enumItem)
		{
			Ucgainstatechange1 = Ucgainstatechange1Info.Ucgainstatechange1ToValue(enumItem);
		}

		public Ucgainstatechange2Enum GetUcgainstatechange2AsUcgainstatechange2Enum()
		{
			return Ucgainstatechange2Info.ValueToUcgainstatechange2(_Ucgainstatechange2);
		}

		public void SetUcgainstatechange2AsUcgainstatechange2Enum(Ucgainstatechange2Enum enumItem)
		{
			Ucgainstatechange2 = Ucgainstatechange2Info.Ucgainstatechange2ToValue(enumItem);
		}

		public Ucgainstatechange3Enum GetUcgainstatechange3AsUcgainstatechange3Enum()
		{
			return Ucgainstatechange3Info.ValueToUcgainstatechange3(_Ucgainstatechange3);
		}

		public void SetUcgainstatechange3AsUcgainstatechange3Enum(Ucgainstatechange3Enum enumItem)
		{
			Ucgainstatechange3 = Ucgainstatechange3Info.Ucgainstatechange3ToValue(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 CommandCompleteForSetGetResetAgcInfo(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.Uccurrentgainstate = bitBuilder.RemoveBitsAsUint(8);
		UserFields.Ucgainstatechange1 = bitBuilder.RemoveBitsAsUint(8);
		UserFields.Ucgainstatechange2 = bitBuilder.RemoveBitsAsUint(8);
		UserFields.Ucgainstatechange3 = 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.Uccurrentgainstate, 8);
		bitBuilder.AddBitsAsUint(UserFields.Ucgainstatechange1, 8);
		bitBuilder.AddBitsAsUint(UserFields.Ucgainstatechange2, 8);
		bitBuilder.AddBitsAsUint(UserFields.Ucgainstatechange3, 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.Uccurrentgainstate > 5)
		{
			list.Add("Maximum allowed value for ucCurrentGainState is 0x5");
		}
		if (UserFields.Ucgainstatechange1 > 5)
		{
			list.Add("Maximum allowed value for ucGainStateChange1 is 0x5");
		}
		if (UserFields.Ucgainstatechange2 > 5)
		{
			list.Add("Maximum allowed value for ucGainStateChange2 is 0x5");
		}
		if (UserFields.Ucgainstatechange3 > 5)
		{
			list.Add("Maximum allowed value for ucGainStateChange3 is 0x5");
		}
		return list;
	}
}
