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

namespace QCRPG.TSL.BT.Packets;

public class DebugConfigureCxmMciLogBitmapCmd : PacketBase
{
	public class UserFieldsWrapper
	{
		public enum SubOpcodeEnum
		{
			HCI_VS_DEBUG_CXM_MCI_LOG_BITMAP_CMD,
			InvalidSubOpcodeValue
		}

		public static class SubOpcodeInfo
		{
			public static SubOpcodeEnum ValueToSubOpcode(uint value)
			{
				if (value == 65)
				{
					return SubOpcodeEnum.HCI_VS_DEBUG_CXM_MCI_LOG_BITMAP_CMD;
				}
				return SubOpcodeEnum.InvalidSubOpcodeValue;
			}

			public static uint SubOpcodeToValue(SubOpcodeEnum enumItem)
			{
				if (enumItem == SubOpcodeEnum.HCI_VS_DEBUG_CXM_MCI_LOG_BITMAP_CMD)
				{
					return 65u;
				}
				return uint.MaxValue;
			}

			public static string SubOpcodeToString(SubOpcodeEnum enumItem)
			{
				if (enumItem == SubOpcodeEnum.HCI_VS_DEBUG_CXM_MCI_LOG_BITMAP_CMD)
				{
					return "HCI_VS_DEBUG_CXM_MCI_LOG_BITMAP_CMD";
				}
				return "Invalid SubOpcode Value";
			}

			public static string SubOpcodeToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("0x41 = HCI_VS_DEBUG_CXM_MCI_LOG_BITMAP_CMD");
				return stringBuilder.ToString();
			}
		}

		public class LogBitmapEnumCollection
		{
		}

		public static class LogBitmapInfo
		{
			public static LogBitmapEnumCollection ValueToLogBitmap(List<uint> valueList)
			{
				return new LogBitmapEnumCollection();
			}

			public static List<uint> LogBitmapToValue(LogBitmapEnumCollection enumCollection)
			{
				return new List<uint>();
			}

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

			public static string LogBitmapToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("Bit 0: Coex Version Query");
				stringBuilder.AppendLine("Bit 1: Coex Version Response");
				stringBuilder.AppendLine("Bit 2: Status Query");
				stringBuilder.AppendLine("Bit 3: Disable BT GPM");
				stringBuilder.AppendLine("Bit 4: WLAN Channels Used");
				stringBuilder.AppendLine("Bit 5: BT Profile Info");
				stringBuilder.AppendLine("Bit 6: BT Status Update");
				stringBuilder.AppendLine("Bit 7: BT Update Flags");
				stringBuilder.AppendLine("Bit 8: BT Scan Update");
				stringBuilder.AppendLine("Bit 9: WLAN R/W BT Priority");
				stringBuilder.AppendLine("Bit 10: BT Pause Profile");
				stringBuilder.AppendLine("Bit 11: BT Scan activity report");
				stringBuilder.AppendLine("Bit 12: BT ACL inactivity report");
				stringBuilder.AppendLine("Bit 13: WLAN set ACL Inactivity Report");
				stringBuilder.AppendLine("Bit 14: Read BT Tx Power");
				stringBuilder.AppendLine("Bit 15: Tx Power Report");
				stringBuilder.AppendLine("Bit 16: Set BT RXSS Minimum Threshold");
				stringBuilder.AppendLine("Bit 17: Query BT RXSS Minimum Threshold");
				stringBuilder.AppendLine("Bit 18: RXSS Minimum Threshold");
				stringBuilder.AppendLine("Bit 19: Scheduling Message Trigger");
				stringBuilder.AppendLine("Bit 20: Scheduling Message Trigger Response");
				stringBuilder.AppendLine("Bit 21: Scan Op");
				stringBuilder.AppendLine("Bit 23: BT Connect Status");
				stringBuilder.AppendLine("Bit 24: Scan Activity Bitmap");
				stringBuilder.AppendLine("Bit 25: BT System Reset");
				stringBuilder.AppendLine("Bit 26: BT Queue Overflow");
				stringBuilder.AppendLine("Bit 27: BT remote registry write–");
				stringBuilder.AppendLine("Bit 28: Report Reg");
				stringBuilder.AppendLine("Bit 29: Pause BT Cal");
				stringBuilder.AppendLine("Bit 30: Request WLAN Update BT Flags");
				stringBuilder.AppendLine("Bit 31: Additional BT Link Info");
				stringBuilder.AppendLine("Bit 32: WLAN Read/Write A2DP Status Thresholds");
				stringBuilder.AppendLine("Bit 33: BT Report A2DP Status Thresholds");
				stringBuilder.AppendLine("Bit 34: BT LE Connection Point Notification");
				stringBuilder.AppendLine("Bit 35: Antenna Auto Isolation Detection – Power Measurement Request");
				stringBuilder.AppendLine("Bit 36: Antenna Auto Isolation Detection – Power Measurement Response");
				stringBuilder.AppendLine("Bit 37: Antenna Auto Isolation Detection – BT Packet TX Status");
				stringBuilder.AppendLine("Bit 38: WLAN Connection Status Report ");
				stringBuilder.AppendLine("Bit 39: BT LE Data Length Request ");
				stringBuilder.AppendLine("Bit 40: BT LE Data Length Response");
				stringBuilder.AppendLine("Bit 41: Concurrent TX on chain0 Request");
				stringBuilder.AppendLine("Bit 42: Concurrent TX on chain0 Response");
				stringBuilder.AppendLine("Bit 43: AIRTIME_STATS_REQUEST");
				stringBuilder.AppendLine("Bit 44: AIRTIME_STATS_RESPONSE");
				stringBuilder.AppendLine("Bit 45: AIRTIME_STATS_STATUS");
				stringBuilder.AppendLine("Bit 46: ACL_INTERACTIVE_STATUS");
				stringBuilder.AppendLine("Bit 47: Advanced BT Profile Info");
				stringBuilder.AppendLine("Bit 48: Advanced BT Connect Status");
				stringBuilder.AppendLine("Bit 49: Advanced BT Status Update");
				stringBuilder.AppendLine("Bit 50: WLAN Status Update");
				stringBuilder.AppendLine("Bit 51: Advanced BT AnchorPointIndication");
				stringBuilder.AppendLine("Bit 52: Wlan Enable Sched Info");
				stringBuilder.AppendLine("Bit 54: Change BT QOS Request");
				stringBuilder.AppendLine("Bit 55: Limit BT Max TX power");
				stringBuilder.AppendLine("Bit 56: Start BT RSSI Reporting");
				stringBuilder.AppendLine("Bit 57: BT report RSSI");
				stringBuilder.AppendLine("Bit 58: BT Delay Indication");
				return stringBuilder.ToString();
			}
		}

		public enum EnableSchedinfoEnum
		{
			DISABLE_SCHEDINFO_LOG_EVENT,
			ENABLE_SCHEDINFO_LOG_EVENT,
			InvalidEnableSchedinfoValue
		}

		public static class EnableSchedinfoInfo
		{
			public static EnableSchedinfoEnum ValueToEnableSchedinfo(uint value)
			{
				return value switch
				{
					0u => EnableSchedinfoEnum.DISABLE_SCHEDINFO_LOG_EVENT, 
					1u => EnableSchedinfoEnum.ENABLE_SCHEDINFO_LOG_EVENT, 
					_ => EnableSchedinfoEnum.InvalidEnableSchedinfoValue, 
				};
			}

			public static uint EnableSchedinfoToValue(EnableSchedinfoEnum enumItem)
			{
				return enumItem switch
				{
					EnableSchedinfoEnum.DISABLE_SCHEDINFO_LOG_EVENT => 0u, 
					EnableSchedinfoEnum.ENABLE_SCHEDINFO_LOG_EVENT => 1u, 
					_ => uint.MaxValue, 
				};
			}

			public static string EnableSchedinfoToString(EnableSchedinfoEnum enumItem)
			{
				return enumItem switch
				{
					EnableSchedinfoEnum.DISABLE_SCHEDINFO_LOG_EVENT => "Disable SchedInfo Log Event", 
					EnableSchedinfoEnum.ENABLE_SCHEDINFO_LOG_EVENT => "Enable SchedInfo Log Event", 
					_ => "Invalid EnableSchedinfo Value", 
				};
			}

			public static string EnableSchedinfoToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("0x0 = Disable SchedInfo Log Event");
				stringBuilder.AppendLine("0x1 = Enable SchedInfo Log Event");
				return stringBuilder.ToString();
			}
		}

		private const uint _SubOpcode = 65u;

		private List<uint> _LogBitmapList = new List<uint>(new uint[16]);

		private uint _EnableSchedinfo;

		public uint SubOpcode => 65u;

		public List<uint> LogBitmapList => _LogBitmapList;

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

		public SubOpcodeEnum GetSubOpcodeAsSubOpcodeEnum()
		{
			return SubOpcodeInfo.ValueToSubOpcode(65u);
		}

		public LogBitmapEnumCollection GetLogBitmapAsLogBitmapEnumCollection()
		{
			return LogBitmapInfo.ValueToLogBitmap(_LogBitmapList);
		}

		public void SetLogBitmapAsLogBitmapEnumCollection(LogBitmapEnumCollection enumCollection)
		{
			_LogBitmapList = LogBitmapInfo.LogBitmapToValue(enumCollection);
		}

		public EnableSchedinfoEnum GetEnableSchedinfoAsEnableSchedinfoEnum()
		{
			return EnableSchedinfoInfo.ValueToEnableSchedinfo(_EnableSchedinfo);
		}

		public void SetEnableSchedinfoAsEnableSchedinfoEnum(EnableSchedinfoEnum enumItem)
		{
			EnableSchedinfo = EnableSchedinfoInfo.EnableSchedinfoToValue(enumItem);
		}
	}

	private const uint _Opcode = 64524u;

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

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

	public uint Opcode => 64524u;

	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;
		}
		if (bitBuilder.RemoveBitsAsUint(8) != UserFields.SubOpcode)
		{
			return false;
		}
		for (int i = 0; i < UserFields.LogBitmapList.Count; i++)
		{
			UserFields.LogBitmapList[i] = bitBuilder.RemoveBitsAsUint(8);
		}
		UserFields.EnableSchedinfo = 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.SubOpcode, 8);
		for (int i = 0; i < UserFields.LogBitmapList.Count; i++)
		{
			if (UserFields.LogBitmapList[i] > 255)
			{
				throw new Exception("UserFields.LogBitmapList[i] is > 0xFF");
			}
			bitBuilder.AddBitsAsUint(UserFields.LogBitmapList[i], 8);
		}
		bitBuilder.AddBitsAsUint(UserFields.EnableSchedinfo, 8);
		_PayloadLength = (uint)((bitBuilder.GetNumberOfBits() - numberOfBits - 8) / 8);
		if ((bitBuilder.GetNumberOfBits() - numberOfBits - 8) % 8 != 0)
		{
			_PayloadLength++;
		}
		bitBuilder.ChangeBitsAsUint(numberOfBits, _PayloadLength, 8);
		return bitBuilder.ToString();
	}
}
