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

namespace QCRPG.TSL.FMHCI.Packets;

public class CommandCompleteForGetStationsInternalDebugParameters : PacketBase
{
	public class UserFieldsWrapper
	{
		public enum BlendEnum
		{
			OFF,
			ON,
			InvalidBlendValue
		}

		public static class BlendInfo
		{
			public static BlendEnum ValueToBlend(uint value)
			{
				return value switch
				{
					0u => BlendEnum.OFF, 
					1u => BlendEnum.ON, 
					_ => BlendEnum.InvalidBlendValue, 
				};
			}

			public static uint BlendToValue(BlendEnum enumItem)
			{
				return enumItem switch
				{
					BlendEnum.OFF => 0u, 
					BlendEnum.ON => 1u, 
					_ => uint.MaxValue, 
				};
			}

			public static string BlendToString(BlendEnum enumItem)
			{
				return enumItem switch
				{
					BlendEnum.OFF => "The currently received audio is mono", 
					BlendEnum.ON => "ON", 
					_ => "Invalid Blend Value", 
				};
			}

			public static string BlendToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("0x0 = The currently received audio is mono");
				stringBuilder.AppendLine("0x1 = ON");
				return stringBuilder.ToString();
			}
		}

		public enum SoftMuteEnum
		{
			OFF,
			ON,
			InvalidSoftMuteValue
		}

		public static class SoftMuteInfo
		{
			public static SoftMuteEnum ValueToSoftMute(uint value)
			{
				return value switch
				{
					0u => SoftMuteEnum.OFF, 
					1u => SoftMuteEnum.ON, 
					_ => SoftMuteEnum.InvalidSoftMuteValue, 
				};
			}

			public static uint SoftMuteToValue(SoftMuteEnum enumItem)
			{
				return enumItem switch
				{
					SoftMuteEnum.OFF => 0u, 
					SoftMuteEnum.ON => 1u, 
					_ => uint.MaxValue, 
				};
			}

			public static string SoftMuteToString(SoftMuteEnum enumItem)
			{
				return enumItem switch
				{
					SoftMuteEnum.OFF => "Soft mute off", 
					SoftMuteEnum.ON => "Soft mute on", 
					_ => "Invalid SoftMute Value", 
				};
			}

			public static string SoftMuteToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("0x0 = Soft mute off");
				stringBuilder.AppendLine("0x1 = Soft mute on");
				return stringBuilder.ToString();
			}
		}

		public enum InterferenceBlendEnum
		{
			OFF,
			ON,
			InvalidInterferenceBlendValue
		}

		public static class InterferenceBlendInfo
		{
			public static InterferenceBlendEnum ValueToInterferenceBlend(uint value)
			{
				return value switch
				{
					0u => InterferenceBlendEnum.OFF, 
					1u => InterferenceBlendEnum.ON, 
					_ => InterferenceBlendEnum.InvalidInterferenceBlendValue, 
				};
			}

			public static uint InterferenceBlendToValue(InterferenceBlendEnum enumItem)
			{
				return enumItem switch
				{
					InterferenceBlendEnum.OFF => 0u, 
					InterferenceBlendEnum.ON => 1u, 
					_ => uint.MaxValue, 
				};
			}

			public static string InterferenceBlendToString(InterferenceBlendEnum enumItem)
			{
				return enumItem switch
				{
					InterferenceBlendEnum.OFF => "Interference mitigated blending off", 
					InterferenceBlendEnum.ON => "Interference mitigated blending on", 
					_ => "Invalid InterferenceBlend Value", 
				};
			}

			public static string InterferenceBlendToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("0x0 = Interference mitigated blending off");
				stringBuilder.AppendLine("0x1 = Interference mitigated blending on");
				return stringBuilder.ToString();
			}
		}

		public enum InterferenceSoftMuteEnum
		{
			OFF,
			ON,
			InvalidInterferenceSoftMuteValue
		}

		public static class InterferenceSoftMuteInfo
		{
			public static InterferenceSoftMuteEnum ValueToInterferenceSoftMute(uint value)
			{
				return value switch
				{
					0u => InterferenceSoftMuteEnum.OFF, 
					1u => InterferenceSoftMuteEnum.ON, 
					_ => InterferenceSoftMuteEnum.InvalidInterferenceSoftMuteValue, 
				};
			}

			public static uint InterferenceSoftMuteToValue(InterferenceSoftMuteEnum enumItem)
			{
				return enumItem switch
				{
					InterferenceSoftMuteEnum.OFF => 0u, 
					InterferenceSoftMuteEnum.ON => 1u, 
					_ => uint.MaxValue, 
				};
			}

			public static string InterferenceSoftMuteToString(InterferenceSoftMuteEnum enumItem)
			{
				return enumItem switch
				{
					InterferenceSoftMuteEnum.OFF => "Interference mitigated soft mute off", 
					InterferenceSoftMuteEnum.ON => "Interference mitigated soft mute on", 
					_ => "Invalid InterferenceSoftMute Value", 
				};
			}

			public static string InterferenceSoftMuteToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("0x0 = Interference mitigated soft mute off");
				stringBuilder.AppendLine("0x1 = Interference mitigated soft mute on");
				return stringBuilder.ToString();
			}
		}

		public enum PilotPllEnum
		{
			OFF,
			ON,
			InvalidPilotPllValue
		}

		public static class PilotPllInfo
		{
			public static PilotPllEnum ValueToPilotPll(uint value)
			{
				return value switch
				{
					0u => PilotPllEnum.OFF, 
					1u => PilotPllEnum.ON, 
					_ => PilotPllEnum.InvalidPilotPllValue, 
				};
			}

			public static uint PilotPllToValue(PilotPllEnum enumItem)
			{
				return enumItem switch
				{
					PilotPllEnum.OFF => 0u, 
					PilotPllEnum.ON => 1u, 
					_ => uint.MaxValue, 
				};
			}

			public static string PilotPllToString(PilotPllEnum enumItem)
			{
				return enumItem switch
				{
					PilotPllEnum.OFF => "Pilot PLL lock off", 
					PilotPllEnum.ON => "Pilot PLL lock on", 
					_ => "Invalid PilotPll Value", 
				};
			}

			public static string PilotPllToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("0x0 = Pilot PLL lock off");
				stringBuilder.AppendLine("0x1 = Pilot PLL lock on");
				return stringBuilder.ToString();
			}
		}

		private const uint _CommandOpcode = 64519u;

		private uint _NumHciCommandPackets;

		private uint _Status;

		private uint _Blend;

		private uint _SoftMute;

		private uint _InterferenceBlend;

		private uint _InterferenceSoftMute;

		private uint _PilotPll;

		private uint _InterferenceToCarrierRatio;

		private uint _InterferenceDetectorOut;

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

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

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

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

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

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

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

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

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

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

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

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

		public BlendEnum GetBlendAsBlendEnum()
		{
			return BlendInfo.ValueToBlend(_Blend);
		}

		public void SetBlendAsBlendEnum(BlendEnum enumItem)
		{
			Blend = BlendInfo.BlendToValue(enumItem);
		}

		public SoftMuteEnum GetSoftMuteAsSoftMuteEnum()
		{
			return SoftMuteInfo.ValueToSoftMute(_SoftMute);
		}

		public void SetSoftMuteAsSoftMuteEnum(SoftMuteEnum enumItem)
		{
			SoftMute = SoftMuteInfo.SoftMuteToValue(enumItem);
		}

		public InterferenceBlendEnum GetInterferenceBlendAsInterferenceBlendEnum()
		{
			return InterferenceBlendInfo.ValueToInterferenceBlend(_InterferenceBlend);
		}

		public void SetInterferenceBlendAsInterferenceBlendEnum(InterferenceBlendEnum enumItem)
		{
			InterferenceBlend = InterferenceBlendInfo.InterferenceBlendToValue(enumItem);
		}

		public InterferenceSoftMuteEnum GetInterferenceSoftMuteAsInterferenceSoftMuteEnum()
		{
			return InterferenceSoftMuteInfo.ValueToInterferenceSoftMute(_InterferenceSoftMute);
		}

		public void SetInterferenceSoftMuteAsInterferenceSoftMuteEnum(InterferenceSoftMuteEnum enumItem)
		{
			InterferenceSoftMute = InterferenceSoftMuteInfo.InterferenceSoftMuteToValue(enumItem);
		}

		public PilotPllEnum GetPilotPllAsPilotPllEnum()
		{
			return PilotPllInfo.ValueToPilotPll(_PilotPll);
		}

		public void SetPilotPllAsPilotPllEnum(PilotPllEnum enumItem)
		{
			PilotPll = PilotPllInfo.PilotPllToValue(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 CommandCompleteForGetStationsInternalDebugParametersInfo(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.Blend = bitBuilder.RemoveBitsAsUint(8);
		UserFields.SoftMute = bitBuilder.RemoveBitsAsUint(8);
		UserFields.InterferenceBlend = bitBuilder.RemoveBitsAsUint(8);
		UserFields.InterferenceSoftMute = bitBuilder.RemoveBitsAsUint(8);
		UserFields.PilotPll = bitBuilder.RemoveBitsAsUint(8);
		UserFields.InterferenceToCarrierRatio = bitBuilder.RemoveBitsAsUint(8);
		UserFields.InterferenceDetectorOut = 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.Blend, 8);
		bitBuilder.AddBitsAsUint(UserFields.SoftMute, 8);
		bitBuilder.AddBitsAsUint(UserFields.InterferenceBlend, 8);
		bitBuilder.AddBitsAsUint(UserFields.InterferenceSoftMute, 8);
		bitBuilder.AddBitsAsUint(UserFields.PilotPll, 8);
		bitBuilder.AddBitsAsUint(UserFields.InterferenceToCarrierRatio, 8);
		bitBuilder.AddBitsAsUint(UserFields.InterferenceDetectorOut, 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.Blend > 1)
		{
			list.Add("Maximum allowed value for Blend is 0x1");
		}
		if (UserFields.SoftMute > 1)
		{
			list.Add("Maximum allowed value for Soft Mute is 0x1");
		}
		if (UserFields.InterferenceBlend > 1)
		{
			list.Add("Maximum allowed value for Interference Blend is 0x1");
		}
		if (UserFields.InterferenceSoftMute > 1)
		{
			list.Add("Maximum allowed value for Interference Soft Mute is 0x1");
		}
		if (UserFields.PilotPll > 1)
		{
			list.Add("Maximum allowed value for Pilot PLL is 0x1");
		}
		return list;
	}
}
