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

namespace QCRPG.TSL.BT.Packets;

public class DebugConfigureCxmLog : PacketBase
{
	public class UserFieldsWrapper
	{
		public enum EnableMciCxmEventEnum
		{
			Disable_MCI_CxM_log_event,
			Enable_MCI_CxM_log_event,
			InvalidEnableMciCxmEventValue
		}

		public static class EnableMciCxmEventInfo
		{
			public static EnableMciCxmEventEnum ValueToEnableMciCxmEvent(uint value)
			{
				return value switch
				{
					0u => EnableMciCxmEventEnum.Disable_MCI_CxM_log_event, 
					1u => EnableMciCxmEventEnum.Enable_MCI_CxM_log_event, 
					_ => EnableMciCxmEventEnum.InvalidEnableMciCxmEventValue, 
				};
			}

			public static uint EnableMciCxmEventToValue(EnableMciCxmEventEnum enumItem)
			{
				return enumItem switch
				{
					EnableMciCxmEventEnum.Disable_MCI_CxM_log_event => 0u, 
					EnableMciCxmEventEnum.Enable_MCI_CxM_log_event => 1u, 
					_ => uint.MaxValue, 
				};
			}

			public static string EnableMciCxmEventToString(EnableMciCxmEventEnum enumItem)
			{
				return enumItem switch
				{
					EnableMciCxmEventEnum.Disable_MCI_CxM_log_event => "Disable MCI CxM log event.", 
					EnableMciCxmEventEnum.Enable_MCI_CxM_log_event => "Enable MCI CxM log event.", 
					_ => "Invalid EnableMciCxmEvent Value", 
				};
			}

			public static string EnableMciCxmEventToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("0x0 = Disable MCI CxM log event.");
				stringBuilder.AppendLine("0x1 = Enable MCI CxM log event.");
				return stringBuilder.ToString();
			}
		}

		public enum ForceAwakeRemoteSleepStateEnum
		{
			Do_not_force_awake_remote_sleep_state_of_WLAN,
			Force_awake_remote_sleep_state_of_WLAN,
			InvalidForceAwakeRemoteSleepStateValue
		}

		public static class ForceAwakeRemoteSleepStateInfo
		{
			public static ForceAwakeRemoteSleepStateEnum ValueToForceAwakeRemoteSleepState(uint value)
			{
				return value switch
				{
					0u => ForceAwakeRemoteSleepStateEnum.Do_not_force_awake_remote_sleep_state_of_WLAN, 
					1u => ForceAwakeRemoteSleepStateEnum.Force_awake_remote_sleep_state_of_WLAN, 
					_ => ForceAwakeRemoteSleepStateEnum.InvalidForceAwakeRemoteSleepStateValue, 
				};
			}

			public static uint ForceAwakeRemoteSleepStateToValue(ForceAwakeRemoteSleepStateEnum enumItem)
			{
				return enumItem switch
				{
					ForceAwakeRemoteSleepStateEnum.Do_not_force_awake_remote_sleep_state_of_WLAN => 0u, 
					ForceAwakeRemoteSleepStateEnum.Force_awake_remote_sleep_state_of_WLAN => 1u, 
					_ => uint.MaxValue, 
				};
			}

			public static string ForceAwakeRemoteSleepStateToString(ForceAwakeRemoteSleepStateEnum enumItem)
			{
				return enumItem switch
				{
					ForceAwakeRemoteSleepStateEnum.Do_not_force_awake_remote_sleep_state_of_WLAN => "Do not force awake remote sleep state of WLAN.", 
					ForceAwakeRemoteSleepStateEnum.Force_awake_remote_sleep_state_of_WLAN => "Force awake remote sleep state of WLAN, i.e., BT always thinks WLAN is awake. This is especially useful if WLAN is either not connected to BT or not awake. This ForceAwakeRemoteSleepState parameter is only valid when EnableMciCxmEvent is 0x01.", 
					_ => "Invalid ForceAwakeRemoteSleepState Value", 
				};
			}

			public static string ForceAwakeRemoteSleepStateToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("0x0 = Do not force awake remote sleep state of WLAN.");
				stringBuilder.AppendLine("0x1 = Force awake remote sleep state of WLAN, i.e., BT always thinks WLAN is awake. This is especially useful if WLAN is either not connected to BT or not awake. This ForceAwakeRemoteSleepState parameter is only valid when EnableMciCxmEvent is 0x01.");
				return stringBuilder.ToString();
			}
		}

		public enum EnableMwsCxmEventEnum
		{
			Disable_MWS_CxM_log_event,
			Enable_MWS_CxM_log_event,
			InvalidEnableMwsCxmEventValue
		}

		public static class EnableMwsCxmEventInfo
		{
			public static EnableMwsCxmEventEnum ValueToEnableMwsCxmEvent(uint value)
			{
				return value switch
				{
					0u => EnableMwsCxmEventEnum.Disable_MWS_CxM_log_event, 
					1u => EnableMwsCxmEventEnum.Enable_MWS_CxM_log_event, 
					_ => EnableMwsCxmEventEnum.InvalidEnableMwsCxmEventValue, 
				};
			}

			public static uint EnableMwsCxmEventToValue(EnableMwsCxmEventEnum enumItem)
			{
				return enumItem switch
				{
					EnableMwsCxmEventEnum.Disable_MWS_CxM_log_event => 0u, 
					EnableMwsCxmEventEnum.Enable_MWS_CxM_log_event => 1u, 
					_ => uint.MaxValue, 
				};
			}

			public static string EnableMwsCxmEventToString(EnableMwsCxmEventEnum enumItem)
			{
				return enumItem switch
				{
					EnableMwsCxmEventEnum.Disable_MWS_CxM_log_event => "Disable MWS CxM log event.", 
					EnableMwsCxmEventEnum.Enable_MWS_CxM_log_event => "Enable MWS CxM log event.", 
					_ => "Invalid EnableMwsCxmEvent Value", 
				};
			}

			public static string EnableMwsCxmEventToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("0x0 = Disable MWS CxM log event.");
				stringBuilder.AppendLine("0x1 = Enable MWS CxM log event.");
				return stringBuilder.ToString();
			}
		}

		private const uint _SubOpcode = 53u;

		private uint _EnableMciCxmEvent;

		private uint _ForceAwakeRemoteSleepState;

		private uint _EnableMwsCxmEvent;

		public uint SubOpcode => 53u;

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

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

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

		public EnableMciCxmEventEnum GetEnableMciCxmEventAsEnableMciCxmEventEnum()
		{
			return EnableMciCxmEventInfo.ValueToEnableMciCxmEvent(_EnableMciCxmEvent);
		}

		public void SetEnableMciCxmEventAsEnableMciCxmEventEnum(EnableMciCxmEventEnum enumItem)
		{
			EnableMciCxmEvent = EnableMciCxmEventInfo.EnableMciCxmEventToValue(enumItem);
		}

		public ForceAwakeRemoteSleepStateEnum GetForceAwakeRemoteSleepStateAsForceAwakeRemoteSleepStateEnum()
		{
			return ForceAwakeRemoteSleepStateInfo.ValueToForceAwakeRemoteSleepState(_ForceAwakeRemoteSleepState);
		}

		public void SetForceAwakeRemoteSleepStateAsForceAwakeRemoteSleepStateEnum(ForceAwakeRemoteSleepStateEnum enumItem)
		{
			ForceAwakeRemoteSleepState = ForceAwakeRemoteSleepStateInfo.ForceAwakeRemoteSleepStateToValue(enumItem);
		}

		public EnableMwsCxmEventEnum GetEnableMwsCxmEventAsEnableMwsCxmEventEnum()
		{
			return EnableMwsCxmEventInfo.ValueToEnableMwsCxmEvent(_EnableMwsCxmEvent);
		}

		public void SetEnableMwsCxmEventAsEnableMwsCxmEventEnum(EnableMwsCxmEventEnum enumItem)
		{
			EnableMwsCxmEvent = EnableMwsCxmEventInfo.EnableMwsCxmEventToValue(enumItem);
		}
	}

	private const uint _Opcode = 64524u;

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

	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 DebugConfigureCxmLogInfo(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;
		}
		UserFields.EnableMciCxmEvent = bitBuilder.RemoveBitsAsUint(8);
		UserFields.ForceAwakeRemoteSleepState = bitBuilder.RemoveBitsAsUint(8);
		UserFields.EnableMwsCxmEvent = 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);
		bitBuilder.AddBitsAsUint(UserFields.EnableMciCxmEvent, 8);
		bitBuilder.AddBitsAsUint(UserFields.ForceAwakeRemoteSleepState, 8);
		bitBuilder.AddBitsAsUint(UserFields.EnableMwsCxmEvent, 8);
		_PayloadLength = (uint)((bitBuilder.GetNumberOfBits() - numberOfBits - 8) / 8);
		if ((bitBuilder.GetNumberOfBits() - numberOfBits - 8) % 8 != 0)
		{
			_PayloadLength++;
		}
		bitBuilder.ChangeBitsAsUint(numberOfBits, _PayloadLength, 8);
		return bitBuilder.ToString();
	}
}
