using System;
using System.Text;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class CommandCompleteForLeGetVendorCapabilities : PacketBase
{
	public class UserFieldsWrapper
	{
		public enum OffloadedResolutionOfPrivateAddressEnum
		{
			Not_capable,
			Capable,
			InvalidOffloadedResolutionOfPrivateAddressValue
		}

		public static class OffloadedResolutionOfPrivateAddressInfo
		{
			public static OffloadedResolutionOfPrivateAddressEnum ValueToOffloadedResolutionOfPrivateAddress(uint value)
			{
				return value switch
				{
					0u => OffloadedResolutionOfPrivateAddressEnum.Not_capable, 
					1u => OffloadedResolutionOfPrivateAddressEnum.Capable, 
					_ => OffloadedResolutionOfPrivateAddressEnum.InvalidOffloadedResolutionOfPrivateAddressValue, 
				};
			}

			public static uint OffloadedResolutionOfPrivateAddressToValue(OffloadedResolutionOfPrivateAddressEnum enumItem)
			{
				return enumItem switch
				{
					OffloadedResolutionOfPrivateAddressEnum.Not_capable => 0u, 
					OffloadedResolutionOfPrivateAddressEnum.Capable => 1u, 
					_ => uint.MaxValue, 
				};
			}

			public static string OffloadedResolutionOfPrivateAddressToString(OffloadedResolutionOfPrivateAddressEnum enumItem)
			{
				return enumItem switch
				{
					OffloadedResolutionOfPrivateAddressEnum.Not_capable => "Not capable", 
					OffloadedResolutionOfPrivateAddressEnum.Capable => "Capable", 
					_ => "Invalid OffloadedResolutionOfPrivateAddress Value", 
				};
			}

			public static string OffloadedResolutionOfPrivateAddressToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("0x0 = Not capable");
				stringBuilder.AppendLine("0x1 = Capable");
				return stringBuilder.ToString();
			}
		}

		public enum FilteringSupportEnum
		{
			Not_supported,
			Supported,
			InvalidFilteringSupportValue
		}

		public static class FilteringSupportInfo
		{
			public static FilteringSupportEnum ValueToFilteringSupport(uint value)
			{
				return value switch
				{
					0u => FilteringSupportEnum.Not_supported, 
					1u => FilteringSupportEnum.Supported, 
					_ => FilteringSupportEnum.InvalidFilteringSupportValue, 
				};
			}

			public static uint FilteringSupportToValue(FilteringSupportEnum enumItem)
			{
				return enumItem switch
				{
					FilteringSupportEnum.Not_supported => 0u, 
					FilteringSupportEnum.Supported => 1u, 
					_ => uint.MaxValue, 
				};
			}

			public static string FilteringSupportToString(FilteringSupportEnum enumItem)
			{
				return enumItem switch
				{
					FilteringSupportEnum.Not_supported => "Not supported", 
					FilteringSupportEnum.Supported => "Supported", 
					_ => "Invalid FilteringSupport Value", 
				};
			}

			public static string FilteringSupportToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("0x0 = Not supported");
				stringBuilder.AppendLine("0x1 = Supported");
				return stringBuilder.ToString();
			}
		}

		public enum ActivityEnergyInfoSupportEnum
		{
			Not_capable,
			Capable,
			InvalidActivityEnergyInfoSupportValue
		}

		public static class ActivityEnergyInfoSupportInfo
		{
			public static ActivityEnergyInfoSupportEnum ValueToActivityEnergyInfoSupport(uint value)
			{
				return value switch
				{
					0u => ActivityEnergyInfoSupportEnum.Not_capable, 
					1u => ActivityEnergyInfoSupportEnum.Capable, 
					_ => ActivityEnergyInfoSupportEnum.InvalidActivityEnergyInfoSupportValue, 
				};
			}

			public static uint ActivityEnergyInfoSupportToValue(ActivityEnergyInfoSupportEnum enumItem)
			{
				return enumItem switch
				{
					ActivityEnergyInfoSupportEnum.Not_capable => 0u, 
					ActivityEnergyInfoSupportEnum.Capable => 1u, 
					_ => uint.MaxValue, 
				};
			}

			public static string ActivityEnergyInfoSupportToString(ActivityEnergyInfoSupportEnum enumItem)
			{
				return enumItem switch
				{
					ActivityEnergyInfoSupportEnum.Not_capable => "Not capable", 
					ActivityEnergyInfoSupportEnum.Capable => "Capable", 
					_ => "Invalid ActivityEnergyInfoSupport Value", 
				};
			}

			public static string ActivityEnergyInfoSupportToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("0x0 = Not capable");
				stringBuilder.AppendLine("0x1 = Capable");
				return stringBuilder.ToString();
			}
		}

		public enum ExtendedScanSupportEnum
		{
			Not_supported,
			Supported,
			InvalidExtendedScanSupportValue
		}

		public static class ExtendedScanSupportInfo
		{
			public static ExtendedScanSupportEnum ValueToExtendedScanSupport(uint value)
			{
				return value switch
				{
					0u => ExtendedScanSupportEnum.Not_supported, 
					1u => ExtendedScanSupportEnum.Supported, 
					_ => ExtendedScanSupportEnum.InvalidExtendedScanSupportValue, 
				};
			}

			public static uint ExtendedScanSupportToValue(ExtendedScanSupportEnum enumItem)
			{
				return enumItem switch
				{
					ExtendedScanSupportEnum.Not_supported => 0u, 
					ExtendedScanSupportEnum.Supported => 1u, 
					_ => uint.MaxValue, 
				};
			}

			public static string ExtendedScanSupportToString(ExtendedScanSupportEnum enumItem)
			{
				return enumItem switch
				{
					ExtendedScanSupportEnum.Not_supported => "Not supported", 
					ExtendedScanSupportEnum.Supported => "Supported", 
					_ => "Invalid ExtendedScanSupport Value", 
				};
			}

			public static string ExtendedScanSupportToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("0x0 = Not supported");
				stringBuilder.AppendLine("0x1 = Supported");
				return stringBuilder.ToString();
			}
		}

		public enum DebugLoggingSupportedEnum
		{
			Not_supported,
			Supported,
			InvalidDebugLoggingSupportedValue
		}

		public static class DebugLoggingSupportedInfo
		{
			public static DebugLoggingSupportedEnum ValueToDebugLoggingSupported(uint value)
			{
				return value switch
				{
					0u => DebugLoggingSupportedEnum.Not_supported, 
					1u => DebugLoggingSupportedEnum.Supported, 
					_ => DebugLoggingSupportedEnum.InvalidDebugLoggingSupportedValue, 
				};
			}

			public static uint DebugLoggingSupportedToValue(DebugLoggingSupportedEnum enumItem)
			{
				return enumItem switch
				{
					DebugLoggingSupportedEnum.Not_supported => 0u, 
					DebugLoggingSupportedEnum.Supported => 1u, 
					_ => uint.MaxValue, 
				};
			}

			public static string DebugLoggingSupportedToString(DebugLoggingSupportedEnum enumItem)
			{
				return enumItem switch
				{
					DebugLoggingSupportedEnum.Not_supported => "Not supported", 
					DebugLoggingSupportedEnum.Supported => "Supported", 
					_ => "Invalid DebugLoggingSupported Value", 
				};
			}

			public static string DebugLoggingSupportedToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("0x0 = Not supported");
				stringBuilder.AppendLine("0x1 = Supported");
				return stringBuilder.ToString();
			}
		}

		private const uint _CommandOpcode = 64851u;

		private uint _NumHciCommandPackets;

		private uint _Status;

		private uint _MaxAdvtInstances;

		private uint _OffloadedResolutionOfPrivateAddress;

		private uint _TotalScanResultsStorage;

		private uint _MaxIrkListSz;

		private uint _FilteringSupport;

		private uint _MaxFilter;

		private uint _ActivityEnergyInfoSupport;

		private uint _VersionSupported;

		private uint _TotalNumOfAdvtTracked;

		private uint _ExtendedScanSupport;

		private uint _DebugLoggingSupported;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

		public OffloadedResolutionOfPrivateAddressEnum GetOffloadedResolutionOfPrivateAddressAsOffloadedResolutionOfPrivateAddressEnum()
		{
			return OffloadedResolutionOfPrivateAddressInfo.ValueToOffloadedResolutionOfPrivateAddress(_OffloadedResolutionOfPrivateAddress);
		}

		public void SetOffloadedResolutionOfPrivateAddressAsOffloadedResolutionOfPrivateAddressEnum(OffloadedResolutionOfPrivateAddressEnum enumItem)
		{
			OffloadedResolutionOfPrivateAddress = OffloadedResolutionOfPrivateAddressInfo.OffloadedResolutionOfPrivateAddressToValue(enumItem);
		}

		public FilteringSupportEnum GetFilteringSupportAsFilteringSupportEnum()
		{
			return FilteringSupportInfo.ValueToFilteringSupport(_FilteringSupport);
		}

		public void SetFilteringSupportAsFilteringSupportEnum(FilteringSupportEnum enumItem)
		{
			FilteringSupport = FilteringSupportInfo.FilteringSupportToValue(enumItem);
		}

		public ActivityEnergyInfoSupportEnum GetActivityEnergyInfoSupportAsActivityEnergyInfoSupportEnum()
		{
			return ActivityEnergyInfoSupportInfo.ValueToActivityEnergyInfoSupport(_ActivityEnergyInfoSupport);
		}

		public void SetActivityEnergyInfoSupportAsActivityEnergyInfoSupportEnum(ActivityEnergyInfoSupportEnum enumItem)
		{
			ActivityEnergyInfoSupport = ActivityEnergyInfoSupportInfo.ActivityEnergyInfoSupportToValue(enumItem);
		}

		public ExtendedScanSupportEnum GetExtendedScanSupportAsExtendedScanSupportEnum()
		{
			return ExtendedScanSupportInfo.ValueToExtendedScanSupport(_ExtendedScanSupport);
		}

		public void SetExtendedScanSupportAsExtendedScanSupportEnum(ExtendedScanSupportEnum enumItem)
		{
			ExtendedScanSupport = ExtendedScanSupportInfo.ExtendedScanSupportToValue(enumItem);
		}

		public DebugLoggingSupportedEnum GetDebugLoggingSupportedAsDebugLoggingSupportedEnum()
		{
			return DebugLoggingSupportedInfo.ValueToDebugLoggingSupported(_DebugLoggingSupported);
		}

		public void SetDebugLoggingSupportedAsDebugLoggingSupportedEnum(DebugLoggingSupportedEnum enumItem)
		{
			DebugLoggingSupported = DebugLoggingSupportedInfo.DebugLoggingSupportedToValue(enumItem);
		}
	}

	private const uint _EventCode = 14u;

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

	private PacketInfoBase info;

	private uint _PayloadLength;

	public UserFieldsWrapper _UserFields = new UserFieldsWrapper();

	public override PacketType Type => PacketType.Notification;

	public override Type[] ExpectedResponseTypes => expectedResponseTypes;

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

	public uint EventCode => 14u;

	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.MaxAdvtInstances = bitBuilder.RemoveBitsAsUint(8);
		UserFields.OffloadedResolutionOfPrivateAddress = bitBuilder.RemoveBitsAsUint(8);
		UserFields.TotalScanResultsStorage = bitBuilder.RemoveBitsAsUintLittleEndian(16);
		UserFields.MaxIrkListSz = bitBuilder.RemoveBitsAsUint(8);
		UserFields.FilteringSupport = bitBuilder.RemoveBitsAsUint(8);
		UserFields.MaxFilter = bitBuilder.RemoveBitsAsUint(8);
		UserFields.ActivityEnergyInfoSupport = bitBuilder.RemoveBitsAsUint(8);
		UserFields.VersionSupported = bitBuilder.RemoveBitsAsUintLittleEndian(16);
		UserFields.TotalNumOfAdvtTracked = bitBuilder.RemoveBitsAsUintLittleEndian(16);
		UserFields.ExtendedScanSupport = bitBuilder.RemoveBitsAsUint(8);
		UserFields.DebugLoggingSupported = 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.MaxAdvtInstances, 8);
		bitBuilder.AddBitsAsUint(UserFields.OffloadedResolutionOfPrivateAddress, 8);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.TotalScanResultsStorage, 16);
		bitBuilder.AddBitsAsUint(UserFields.MaxIrkListSz, 8);
		bitBuilder.AddBitsAsUint(UserFields.FilteringSupport, 8);
		bitBuilder.AddBitsAsUint(UserFields.MaxFilter, 8);
		bitBuilder.AddBitsAsUint(UserFields.ActivityEnergyInfoSupport, 8);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.VersionSupported, 16);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.TotalNumOfAdvtTracked, 16);
		bitBuilder.AddBitsAsUint(UserFields.ExtendedScanSupport, 8);
		bitBuilder.AddBitsAsUint(UserFields.DebugLoggingSupported, 8);
		_PayloadLength = (uint)((bitBuilder.GetNumberOfBits() - numberOfBits - 8) / 8);
		if ((bitBuilder.GetNumberOfBits() - numberOfBits - 8) % 8 != 0)
		{
			_PayloadLength++;
		}
		bitBuilder.ChangeBitsAsUint(numberOfBits, _PayloadLength, 8);
		return bitBuilder.ToString();
	}
}
