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

namespace QCRPG.TSL.BT.Packets;

public class DbfwScoDebugInfo : PacketBase
{
	public class UserFieldsWrapper
	{
		public class FlagsEnumCollection
		{
		}

		public static class FlagsInfo
		{
			public static FlagsEnumCollection ValueToFlags(uint value)
			{
				return new FlagsEnumCollection();
			}

			public static uint FlagsToValue(FlagsEnumCollection enumCollection)
			{
				return 0u;
			}

			public static string FlagsToString(FlagsEnumCollection enumCollection)
			{
				string text = "";
				return text.TrimEnd('\r', '\n');
			}

			public static string FlagsToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("Bit 0: Count Null Packet");
				stringBuilder.AppendLine("Bit 1: Master Role");
				return stringBuilder.ToString();
			}
		}

		public enum ScoEscoModeEnum
		{
			SCO,
			eSCO,
			RESERVED_FOR_FUTURE_USE,
			InvalidScoEscoModeValue
		}

		public static class ScoEscoModeInfo
		{
			public static ScoEscoModeEnum ValueToScoEscoMode(uint value)
			{
				switch (value)
				{
				case 0u:
					return ScoEscoModeEnum.SCO;
				case 1u:
					return ScoEscoModeEnum.eSCO;
				default:
					if (value >= 2 && value <= 255)
					{
						return ScoEscoModeEnum.RESERVED_FOR_FUTURE_USE;
					}
					return ScoEscoModeEnum.InvalidScoEscoModeValue;
				}
			}

			public static uint ScoEscoModeToValue(ScoEscoModeEnum enumItem)
			{
				return enumItem switch
				{
					ScoEscoModeEnum.SCO => 0u, 
					ScoEscoModeEnum.eSCO => 1u, 
					ScoEscoModeEnum.RESERVED_FOR_FUTURE_USE => 2u, 
					_ => uint.MaxValue, 
				};
			}

			public static string ScoEscoModeToString(ScoEscoModeEnum enumItem)
			{
				return enumItem switch
				{
					ScoEscoModeEnum.SCO => "SCO", 
					ScoEscoModeEnum.eSCO => "eSCO", 
					ScoEscoModeEnum.RESERVED_FOR_FUTURE_USE => "RESERVED_FOR_FUTURE_USE", 
					_ => "Invalid ScoEscoMode Value", 
				};
			}

			public static string ScoEscoModeToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("0x0 = SCO");
				stringBuilder.AppendLine("0x1 = eSCO");
				stringBuilder.AppendLine("0x2-0xFF = RESERVED_FOR_FUTURE_USE");
				return stringBuilder.ToString();
			}
		}

		private const uint _DbfwEventCode = 144u;

		private const uint _SubEventCode = 49u;

		private uint _ConnectionHandle;

		private uint _Flags;

		private uint _ScoEscoMode;

		private uint _TxConsecutiveDroppedPacketGroup1;

		private uint _TxConsecutiveDroppedPacketGroup2;

		private uint _TxConsecutiveDroppedPacketGroup3;

		private uint _TxConsecutiveDroppedPacketGroup4;

		private uint _TxConsecutiveDroppedPacketGroup5;

		private uint _TxConsecutiveMissedPacketGroup1;

		private uint _TxConsecutiveMissedPacketGroup2;

		private uint _TxConsecutiveMissedPacketGroup3;

		private uint _TxConsecutiveMissedPacketGroup4;

		private uint _TxConsecutiveMissedPacketGroup5;

		private uint _RxConsecutiveDroppedPacketGroup1;

		private uint _RxConsecutiveDroppedPacketGroup2;

		private uint _RxConsecutiveDroppedPacketGroup3;

		private uint _RxConsecutiveDroppedPacketGroup4;

		private uint _RxConsecutiveDroppedPacketGroup5;

		private uint _RxConsecutiveMissedPacketGroup1;

		private uint _RxConsecutiveMissedPacketGroup2;

		private uint _RxConsecutiveMissedPacketGroup3;

		private uint _RxConsecutiveMissedPacketGroup4;

		private uint _RxConsecutiveMissedPacketGroup5;

		private uint _TxRetransmittedPacketGroup1;

		private uint _TxRetransmittedPacketGroup2;

		private uint _TxRetransmittedPacketGroup3;

		private uint _TxRetransmittedPacketGroup4;

		private uint _TxRetransmittedPacketGroup5;

		private uint _RxRetransmittedPacketGroup1;

		private uint _RxRetransmittedPacketGroup2;

		private uint _RxRetransmittedPacketGroup3;

		private uint _RxRetransmittedPacketGroup4;

		private uint _RxRetransmittedPacketGroup5;

		public uint DbfwEventCode => 144u;

		public uint SubEventCode => 49u;

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

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

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

		public uint TxConsecutiveDroppedPacketGroup1
		{
			get
			{
				return _TxConsecutiveDroppedPacketGroup1;
			}
			set
			{
				_TxConsecutiveDroppedPacketGroup1 = value;
			}
		}

		public uint TxConsecutiveDroppedPacketGroup2
		{
			get
			{
				return _TxConsecutiveDroppedPacketGroup2;
			}
			set
			{
				_TxConsecutiveDroppedPacketGroup2 = value;
			}
		}

		public uint TxConsecutiveDroppedPacketGroup3
		{
			get
			{
				return _TxConsecutiveDroppedPacketGroup3;
			}
			set
			{
				_TxConsecutiveDroppedPacketGroup3 = value;
			}
		}

		public uint TxConsecutiveDroppedPacketGroup4
		{
			get
			{
				return _TxConsecutiveDroppedPacketGroup4;
			}
			set
			{
				_TxConsecutiveDroppedPacketGroup4 = value;
			}
		}

		public uint TxConsecutiveDroppedPacketGroup5
		{
			get
			{
				return _TxConsecutiveDroppedPacketGroup5;
			}
			set
			{
				_TxConsecutiveDroppedPacketGroup5 = value;
			}
		}

		public uint TxConsecutiveMissedPacketGroup1
		{
			get
			{
				return _TxConsecutiveMissedPacketGroup1;
			}
			set
			{
				_TxConsecutiveMissedPacketGroup1 = value;
			}
		}

		public uint TxConsecutiveMissedPacketGroup2
		{
			get
			{
				return _TxConsecutiveMissedPacketGroup2;
			}
			set
			{
				_TxConsecutiveMissedPacketGroup2 = value;
			}
		}

		public uint TxConsecutiveMissedPacketGroup3
		{
			get
			{
				return _TxConsecutiveMissedPacketGroup3;
			}
			set
			{
				_TxConsecutiveMissedPacketGroup3 = value;
			}
		}

		public uint TxConsecutiveMissedPacketGroup4
		{
			get
			{
				return _TxConsecutiveMissedPacketGroup4;
			}
			set
			{
				_TxConsecutiveMissedPacketGroup4 = value;
			}
		}

		public uint TxConsecutiveMissedPacketGroup5
		{
			get
			{
				return _TxConsecutiveMissedPacketGroup5;
			}
			set
			{
				_TxConsecutiveMissedPacketGroup5 = value;
			}
		}

		public uint RxConsecutiveDroppedPacketGroup1
		{
			get
			{
				return _RxConsecutiveDroppedPacketGroup1;
			}
			set
			{
				_RxConsecutiveDroppedPacketGroup1 = value;
			}
		}

		public uint RxConsecutiveDroppedPacketGroup2
		{
			get
			{
				return _RxConsecutiveDroppedPacketGroup2;
			}
			set
			{
				_RxConsecutiveDroppedPacketGroup2 = value;
			}
		}

		public uint RxConsecutiveDroppedPacketGroup3
		{
			get
			{
				return _RxConsecutiveDroppedPacketGroup3;
			}
			set
			{
				_RxConsecutiveDroppedPacketGroup3 = value;
			}
		}

		public uint RxConsecutiveDroppedPacketGroup4
		{
			get
			{
				return _RxConsecutiveDroppedPacketGroup4;
			}
			set
			{
				_RxConsecutiveDroppedPacketGroup4 = value;
			}
		}

		public uint RxConsecutiveDroppedPacketGroup5
		{
			get
			{
				return _RxConsecutiveDroppedPacketGroup5;
			}
			set
			{
				_RxConsecutiveDroppedPacketGroup5 = value;
			}
		}

		public uint RxConsecutiveMissedPacketGroup1
		{
			get
			{
				return _RxConsecutiveMissedPacketGroup1;
			}
			set
			{
				_RxConsecutiveMissedPacketGroup1 = value;
			}
		}

		public uint RxConsecutiveMissedPacketGroup2
		{
			get
			{
				return _RxConsecutiveMissedPacketGroup2;
			}
			set
			{
				_RxConsecutiveMissedPacketGroup2 = value;
			}
		}

		public uint RxConsecutiveMissedPacketGroup3
		{
			get
			{
				return _RxConsecutiveMissedPacketGroup3;
			}
			set
			{
				_RxConsecutiveMissedPacketGroup3 = value;
			}
		}

		public uint RxConsecutiveMissedPacketGroup4
		{
			get
			{
				return _RxConsecutiveMissedPacketGroup4;
			}
			set
			{
				_RxConsecutiveMissedPacketGroup4 = value;
			}
		}

		public uint RxConsecutiveMissedPacketGroup5
		{
			get
			{
				return _RxConsecutiveMissedPacketGroup5;
			}
			set
			{
				_RxConsecutiveMissedPacketGroup5 = value;
			}
		}

		public uint TxRetransmittedPacketGroup1
		{
			get
			{
				return _TxRetransmittedPacketGroup1;
			}
			set
			{
				_TxRetransmittedPacketGroup1 = value;
			}
		}

		public uint TxRetransmittedPacketGroup2
		{
			get
			{
				return _TxRetransmittedPacketGroup2;
			}
			set
			{
				_TxRetransmittedPacketGroup2 = value;
			}
		}

		public uint TxRetransmittedPacketGroup3
		{
			get
			{
				return _TxRetransmittedPacketGroup3;
			}
			set
			{
				_TxRetransmittedPacketGroup3 = value;
			}
		}

		public uint TxRetransmittedPacketGroup4
		{
			get
			{
				return _TxRetransmittedPacketGroup4;
			}
			set
			{
				_TxRetransmittedPacketGroup4 = value;
			}
		}

		public uint TxRetransmittedPacketGroup5
		{
			get
			{
				return _TxRetransmittedPacketGroup5;
			}
			set
			{
				_TxRetransmittedPacketGroup5 = value;
			}
		}

		public uint RxRetransmittedPacketGroup1
		{
			get
			{
				return _RxRetransmittedPacketGroup1;
			}
			set
			{
				_RxRetransmittedPacketGroup1 = value;
			}
		}

		public uint RxRetransmittedPacketGroup2
		{
			get
			{
				return _RxRetransmittedPacketGroup2;
			}
			set
			{
				_RxRetransmittedPacketGroup2 = value;
			}
		}

		public uint RxRetransmittedPacketGroup3
		{
			get
			{
				return _RxRetransmittedPacketGroup3;
			}
			set
			{
				_RxRetransmittedPacketGroup3 = value;
			}
		}

		public uint RxRetransmittedPacketGroup4
		{
			get
			{
				return _RxRetransmittedPacketGroup4;
			}
			set
			{
				_RxRetransmittedPacketGroup4 = value;
			}
		}

		public uint RxRetransmittedPacketGroup5
		{
			get
			{
				return _RxRetransmittedPacketGroup5;
			}
			set
			{
				_RxRetransmittedPacketGroup5 = value;
			}
		}

		public FlagsEnumCollection GetFlagsAsFlagsEnumCollection()
		{
			return FlagsInfo.ValueToFlags(_Flags);
		}

		public void SetFlagsAsFlagsEnumCollection(FlagsEnumCollection enumCollection)
		{
			Flags = FlagsInfo.FlagsToValue(enumCollection);
		}

		public ScoEscoModeEnum GetScoEscoModeAsScoEscoModeEnum()
		{
			return ScoEscoModeInfo.ValueToScoEscoMode(_ScoEscoMode);
		}

		public void SetScoEscoModeAsScoEscoModeEnum(ScoEscoModeEnum enumItem)
		{
			ScoEscoMode = ScoEscoModeInfo.ScoEscoModeToValue(enumItem);
		}
	}

	private const uint _EventCode = 255u;

	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 DbfwScoDebugInfoInfo(this);
			}
			return info;
		}
	}

	public uint EventCode => 255u;

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

	public UserFieldsWrapper UserFields => _UserFields;

	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;
		}
		if (bitBuilder.RemoveBitsAsUint(8) != UserFields.DbfwEventCode)
		{
			return false;
		}
		if (bitBuilder.RemoveBitsAsUint(8) != UserFields.SubEventCode)
		{
			return false;
		}
		UserFields.ConnectionHandle = bitBuilder.RemoveBitsAsUintLittleEndian(16);
		UserFields.Flags = bitBuilder.RemoveBitsAsUint(8);
		UserFields.ScoEscoMode = bitBuilder.RemoveBitsAsUint(8);
		UserFields.TxConsecutiveDroppedPacketGroup1 = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.TxConsecutiveDroppedPacketGroup2 = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.TxConsecutiveDroppedPacketGroup3 = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.TxConsecutiveDroppedPacketGroup4 = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.TxConsecutiveDroppedPacketGroup5 = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.TxConsecutiveMissedPacketGroup1 = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.TxConsecutiveMissedPacketGroup2 = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.TxConsecutiveMissedPacketGroup3 = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.TxConsecutiveMissedPacketGroup4 = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.TxConsecutiveMissedPacketGroup5 = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.RxConsecutiveDroppedPacketGroup1 = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.RxConsecutiveDroppedPacketGroup2 = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.RxConsecutiveDroppedPacketGroup3 = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.RxConsecutiveDroppedPacketGroup4 = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.RxConsecutiveDroppedPacketGroup5 = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.RxConsecutiveMissedPacketGroup1 = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.RxConsecutiveMissedPacketGroup2 = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.RxConsecutiveMissedPacketGroup3 = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.RxConsecutiveMissedPacketGroup4 = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.RxConsecutiveMissedPacketGroup5 = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.TxRetransmittedPacketGroup1 = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.TxRetransmittedPacketGroup2 = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.TxRetransmittedPacketGroup3 = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.TxRetransmittedPacketGroup4 = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.TxRetransmittedPacketGroup5 = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.RxRetransmittedPacketGroup1 = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.RxRetransmittedPacketGroup2 = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.RxRetransmittedPacketGroup3 = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.RxRetransmittedPacketGroup4 = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		UserFields.RxRetransmittedPacketGroup5 = bitBuilder.RemoveBitsAsUintLittleEndian(32);
		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.DbfwEventCode, 8);
		bitBuilder.AddBitsAsUint(UserFields.SubEventCode, 8);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.ConnectionHandle, 16);
		bitBuilder.AddBitsAsUint(UserFields.Flags, 8);
		bitBuilder.AddBitsAsUint(UserFields.ScoEscoMode, 8);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.TxConsecutiveDroppedPacketGroup1, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.TxConsecutiveDroppedPacketGroup2, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.TxConsecutiveDroppedPacketGroup3, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.TxConsecutiveDroppedPacketGroup4, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.TxConsecutiveDroppedPacketGroup5, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.TxConsecutiveMissedPacketGroup1, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.TxConsecutiveMissedPacketGroup2, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.TxConsecutiveMissedPacketGroup3, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.TxConsecutiveMissedPacketGroup4, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.TxConsecutiveMissedPacketGroup5, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.RxConsecutiveDroppedPacketGroup1, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.RxConsecutiveDroppedPacketGroup2, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.RxConsecutiveDroppedPacketGroup3, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.RxConsecutiveDroppedPacketGroup4, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.RxConsecutiveDroppedPacketGroup5, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.RxConsecutiveMissedPacketGroup1, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.RxConsecutiveMissedPacketGroup2, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.RxConsecutiveMissedPacketGroup3, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.RxConsecutiveMissedPacketGroup4, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.RxConsecutiveMissedPacketGroup5, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.TxRetransmittedPacketGroup1, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.TxRetransmittedPacketGroup2, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.TxRetransmittedPacketGroup3, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.TxRetransmittedPacketGroup4, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.TxRetransmittedPacketGroup5, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.RxRetransmittedPacketGroup1, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.RxRetransmittedPacketGroup2, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.RxRetransmittedPacketGroup3, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.RxRetransmittedPacketGroup4, 32);
		bitBuilder.AddBitsAsUintLittleEndian(UserFields.RxRetransmittedPacketGroup5, 32);
		_PayloadLength = (uint)((bitBuilder.GetNumberOfBits() - numberOfBits - 8) / 8);
		if ((bitBuilder.GetNumberOfBits() - numberOfBits - 8) % 8 != 0)
		{
			_PayloadLength++;
		}
		bitBuilder.ChangeBitsAsUint(numberOfBits, _PayloadLength, 8);
		return bitBuilder.ToString();
	}
}
