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

namespace QCRPG.TSL.BT.Packets;

public class SetEventMaskPage2 : PacketBase
{
	public class UserFieldsWrapper
	{
		public class EventMaskPage2EnumCollection
		{
			private EnableBitEnum _PhysicalLinkCompleteEvent;

			private EnableBitEnum _ChannelSelectedEvent;

			private EnableBitEnum _DisconnectionPhysicalLinkEvent;

			private EnableBitEnum _PhysicalLinkLossEarlyWarningEvent;

			private EnableBitEnum _PhysicalLinkRecoveryEvent;

			private EnableBitEnum _LogicalLinkCompleteEvent;

			private EnableBitEnum _DisconnectionLogicalLinkCompleteEvent;

			private EnableBitEnum _FlowSpecModifyCompleteEvent;

			private EnableBitEnum _NumberOfCompletedDataBlocksEvent;

			private EnableBitEnum _AmpStartTestEvent;

			private EnableBitEnum _AmpTestEndEvent;

			private EnableBitEnum _AmpReceiverReportEvent;

			private EnableBitEnum _ShortRangeModeChangeCompleteEvent;

			private EnableBitEnum _AmpStatusChangeEvent;

			private EnableBitEnum _TriggeredClockCaptureEvent;

			private EnableBitEnum _SynchronizationTrainCompleteEvent;

			private EnableBitEnum _SynchronizationTrainReceivedEvent;

			private EnableBitEnum _ConnectionlessSlaveBroadcastReceiveEvent;

			private EnableBitEnum _ConnectionlessSlaveBroadcastTimeoutEvent;

			private EnableBitEnum _TruncatedPageCompleteEvent;

			private EnableBitEnum _SlavePageResponseTimeoutEvent;

			private EnableBitEnum _ConnectionlessSlaveBroadcastChannelMapChangeEvent;

			private EnableBitEnum _InquiryResponseNotificationEvent;

			private EnableBitEnum _AuthenticatedPayloadTimeoutExpiredEvent;

			public EnableBitEnum PhysicalLinkCompleteEvent
			{
				get
				{
					return _PhysicalLinkCompleteEvent;
				}
				set
				{
					_PhysicalLinkCompleteEvent = value;
				}
			}

			public EnableBitEnum ChannelSelectedEvent
			{
				get
				{
					return _ChannelSelectedEvent;
				}
				set
				{
					_ChannelSelectedEvent = value;
				}
			}

			public EnableBitEnum DisconnectionPhysicalLinkEvent
			{
				get
				{
					return _DisconnectionPhysicalLinkEvent;
				}
				set
				{
					_DisconnectionPhysicalLinkEvent = value;
				}
			}

			public EnableBitEnum PhysicalLinkLossEarlyWarningEvent
			{
				get
				{
					return _PhysicalLinkLossEarlyWarningEvent;
				}
				set
				{
					_PhysicalLinkLossEarlyWarningEvent = value;
				}
			}

			public EnableBitEnum PhysicalLinkRecoveryEvent
			{
				get
				{
					return _PhysicalLinkRecoveryEvent;
				}
				set
				{
					_PhysicalLinkRecoveryEvent = value;
				}
			}

			public EnableBitEnum LogicalLinkCompleteEvent
			{
				get
				{
					return _LogicalLinkCompleteEvent;
				}
				set
				{
					_LogicalLinkCompleteEvent = value;
				}
			}

			public EnableBitEnum DisconnectionLogicalLinkCompleteEvent
			{
				get
				{
					return _DisconnectionLogicalLinkCompleteEvent;
				}
				set
				{
					_DisconnectionLogicalLinkCompleteEvent = value;
				}
			}

			public EnableBitEnum FlowSpecModifyCompleteEvent
			{
				get
				{
					return _FlowSpecModifyCompleteEvent;
				}
				set
				{
					_FlowSpecModifyCompleteEvent = value;
				}
			}

			public EnableBitEnum NumberOfCompletedDataBlocksEvent
			{
				get
				{
					return _NumberOfCompletedDataBlocksEvent;
				}
				set
				{
					_NumberOfCompletedDataBlocksEvent = value;
				}
			}

			public EnableBitEnum AmpStartTestEvent
			{
				get
				{
					return _AmpStartTestEvent;
				}
				set
				{
					_AmpStartTestEvent = value;
				}
			}

			public EnableBitEnum AmpTestEndEvent
			{
				get
				{
					return _AmpTestEndEvent;
				}
				set
				{
					_AmpTestEndEvent = value;
				}
			}

			public EnableBitEnum AmpReceiverReportEvent
			{
				get
				{
					return _AmpReceiverReportEvent;
				}
				set
				{
					_AmpReceiverReportEvent = value;
				}
			}

			public EnableBitEnum ShortRangeModeChangeCompleteEvent
			{
				get
				{
					return _ShortRangeModeChangeCompleteEvent;
				}
				set
				{
					_ShortRangeModeChangeCompleteEvent = value;
				}
			}

			public EnableBitEnum AmpStatusChangeEvent
			{
				get
				{
					return _AmpStatusChangeEvent;
				}
				set
				{
					_AmpStatusChangeEvent = value;
				}
			}

			public EnableBitEnum TriggeredClockCaptureEvent
			{
				get
				{
					return _TriggeredClockCaptureEvent;
				}
				set
				{
					_TriggeredClockCaptureEvent = value;
				}
			}

			public EnableBitEnum SynchronizationTrainCompleteEvent
			{
				get
				{
					return _SynchronizationTrainCompleteEvent;
				}
				set
				{
					_SynchronizationTrainCompleteEvent = value;
				}
			}

			public EnableBitEnum SynchronizationTrainReceivedEvent
			{
				get
				{
					return _SynchronizationTrainReceivedEvent;
				}
				set
				{
					_SynchronizationTrainReceivedEvent = value;
				}
			}

			public EnableBitEnum ConnectionlessSlaveBroadcastReceiveEvent
			{
				get
				{
					return _ConnectionlessSlaveBroadcastReceiveEvent;
				}
				set
				{
					_ConnectionlessSlaveBroadcastReceiveEvent = value;
				}
			}

			public EnableBitEnum ConnectionlessSlaveBroadcastTimeoutEvent
			{
				get
				{
					return _ConnectionlessSlaveBroadcastTimeoutEvent;
				}
				set
				{
					_ConnectionlessSlaveBroadcastTimeoutEvent = value;
				}
			}

			public EnableBitEnum TruncatedPageCompleteEvent
			{
				get
				{
					return _TruncatedPageCompleteEvent;
				}
				set
				{
					_TruncatedPageCompleteEvent = value;
				}
			}

			public EnableBitEnum SlavePageResponseTimeoutEvent
			{
				get
				{
					return _SlavePageResponseTimeoutEvent;
				}
				set
				{
					_SlavePageResponseTimeoutEvent = value;
				}
			}

			public EnableBitEnum ConnectionlessSlaveBroadcastChannelMapChangeEvent
			{
				get
				{
					return _ConnectionlessSlaveBroadcastChannelMapChangeEvent;
				}
				set
				{
					_ConnectionlessSlaveBroadcastChannelMapChangeEvent = value;
				}
			}

			public EnableBitEnum InquiryResponseNotificationEvent
			{
				get
				{
					return _InquiryResponseNotificationEvent;
				}
				set
				{
					_InquiryResponseNotificationEvent = value;
				}
			}

			public EnableBitEnum AuthenticatedPayloadTimeoutExpiredEvent
			{
				get
				{
					return _AuthenticatedPayloadTimeoutExpiredEvent;
				}
				set
				{
					_AuthenticatedPayloadTimeoutExpiredEvent = value;
				}
			}
		}

		public static class EventMaskPage2Info
		{
			public static EventMaskPage2EnumCollection ValueToEventMaskPage2(ulong value)
			{
				EventMaskPage2EnumCollection eventMaskPage2EnumCollection = new EventMaskPage2EnumCollection();
				eventMaskPage2EnumCollection.PhysicalLinkCompleteEvent = EnableBitInfo.ValueToEnableBit((uint)(value & 1));
				eventMaskPage2EnumCollection.ChannelSelectedEvent = EnableBitInfo.ValueToEnableBit((uint)((value & 2) >> 1));
				eventMaskPage2EnumCollection.DisconnectionPhysicalLinkEvent = EnableBitInfo.ValueToEnableBit((uint)((value & 4) >> 2));
				eventMaskPage2EnumCollection.PhysicalLinkLossEarlyWarningEvent = EnableBitInfo.ValueToEnableBit((uint)((value & 8) >> 3));
				eventMaskPage2EnumCollection.PhysicalLinkRecoveryEvent = EnableBitInfo.ValueToEnableBit((uint)((value & 0x10) >> 4));
				eventMaskPage2EnumCollection.LogicalLinkCompleteEvent = EnableBitInfo.ValueToEnableBit((uint)((value & 0x20) >> 5));
				eventMaskPage2EnumCollection.DisconnectionLogicalLinkCompleteEvent = EnableBitInfo.ValueToEnableBit((uint)((value & 0x40) >> 6));
				eventMaskPage2EnumCollection.FlowSpecModifyCompleteEvent = EnableBitInfo.ValueToEnableBit((uint)((value & 0x80) >> 7));
				eventMaskPage2EnumCollection.NumberOfCompletedDataBlocksEvent = EnableBitInfo.ValueToEnableBit((uint)((value & 0x100) >> 8));
				eventMaskPage2EnumCollection.AmpStartTestEvent = EnableBitInfo.ValueToEnableBit((uint)((value & 0x200) >> 9));
				eventMaskPage2EnumCollection.AmpTestEndEvent = EnableBitInfo.ValueToEnableBit((uint)((value & 0x400) >> 10));
				eventMaskPage2EnumCollection.AmpReceiverReportEvent = EnableBitInfo.ValueToEnableBit((uint)((value & 0x800) >> 11));
				eventMaskPage2EnumCollection.ShortRangeModeChangeCompleteEvent = EnableBitInfo.ValueToEnableBit((uint)((value & 0x1000) >> 12));
				eventMaskPage2EnumCollection.AmpStatusChangeEvent = EnableBitInfo.ValueToEnableBit((uint)((value & 0x2000) >> 13));
				eventMaskPage2EnumCollection.TriggeredClockCaptureEvent = EnableBitInfo.ValueToEnableBit((uint)((value & 0x4000) >> 14));
				eventMaskPage2EnumCollection.SynchronizationTrainCompleteEvent = EnableBitInfo.ValueToEnableBit((uint)((value & 0x8000) >> 15));
				eventMaskPage2EnumCollection.SynchronizationTrainReceivedEvent = EnableBitInfo.ValueToEnableBit((uint)((value & 0x10000) >> 16));
				eventMaskPage2EnumCollection.ConnectionlessSlaveBroadcastReceiveEvent = EnableBitInfo.ValueToEnableBit((uint)((value & 0x20000) >> 17));
				eventMaskPage2EnumCollection.ConnectionlessSlaveBroadcastTimeoutEvent = EnableBitInfo.ValueToEnableBit((uint)((value & 0x40000) >> 18));
				eventMaskPage2EnumCollection.TruncatedPageCompleteEvent = EnableBitInfo.ValueToEnableBit((uint)((value & 0x80000) >> 19));
				eventMaskPage2EnumCollection.SlavePageResponseTimeoutEvent = EnableBitInfo.ValueToEnableBit((uint)((value & 0x100000) >> 20));
				eventMaskPage2EnumCollection.ConnectionlessSlaveBroadcastChannelMapChangeEvent = EnableBitInfo.ValueToEnableBit((uint)((value & 0x200000) >> 21));
				eventMaskPage2EnumCollection.InquiryResponseNotificationEvent = EnableBitInfo.ValueToEnableBit((uint)((value & 0x400000) >> 22));
				eventMaskPage2EnumCollection.AuthenticatedPayloadTimeoutExpiredEvent = EnableBitInfo.ValueToEnableBit((uint)((value & 0x800000) >> 23));
				return eventMaskPage2EnumCollection;
			}

			public static ulong EventMaskPage2ToValue(EventMaskPage2EnumCollection enumCollection)
			{
				ulong num = 0uL;
				num |= EnableBitInfo.EnableBitToValue(enumCollection.PhysicalLinkCompleteEvent);
				num |= EnableBitInfo.EnableBitToValue(enumCollection.ChannelSelectedEvent) << 1;
				num |= EnableBitInfo.EnableBitToValue(enumCollection.DisconnectionPhysicalLinkEvent) << 2;
				num |= EnableBitInfo.EnableBitToValue(enumCollection.PhysicalLinkLossEarlyWarningEvent) << 3;
				num |= EnableBitInfo.EnableBitToValue(enumCollection.PhysicalLinkRecoveryEvent) << 4;
				num |= EnableBitInfo.EnableBitToValue(enumCollection.LogicalLinkCompleteEvent) << 5;
				num |= EnableBitInfo.EnableBitToValue(enumCollection.DisconnectionLogicalLinkCompleteEvent) << 6;
				num |= EnableBitInfo.EnableBitToValue(enumCollection.FlowSpecModifyCompleteEvent) << 7;
				num |= EnableBitInfo.EnableBitToValue(enumCollection.NumberOfCompletedDataBlocksEvent) << 8;
				num |= EnableBitInfo.EnableBitToValue(enumCollection.AmpStartTestEvent) << 9;
				num |= EnableBitInfo.EnableBitToValue(enumCollection.AmpTestEndEvent) << 10;
				num |= EnableBitInfo.EnableBitToValue(enumCollection.AmpReceiverReportEvent) << 11;
				num |= EnableBitInfo.EnableBitToValue(enumCollection.ShortRangeModeChangeCompleteEvent) << 12;
				num |= EnableBitInfo.EnableBitToValue(enumCollection.AmpStatusChangeEvent) << 13;
				num |= EnableBitInfo.EnableBitToValue(enumCollection.TriggeredClockCaptureEvent) << 14;
				num |= EnableBitInfo.EnableBitToValue(enumCollection.SynchronizationTrainCompleteEvent) << 15;
				num |= EnableBitInfo.EnableBitToValue(enumCollection.SynchronizationTrainReceivedEvent) << 16;
				num |= EnableBitInfo.EnableBitToValue(enumCollection.ConnectionlessSlaveBroadcastReceiveEvent) << 17;
				num |= EnableBitInfo.EnableBitToValue(enumCollection.ConnectionlessSlaveBroadcastTimeoutEvent) << 18;
				num |= EnableBitInfo.EnableBitToValue(enumCollection.TruncatedPageCompleteEvent) << 19;
				num |= EnableBitInfo.EnableBitToValue(enumCollection.SlavePageResponseTimeoutEvent) << 20;
				num |= EnableBitInfo.EnableBitToValue(enumCollection.ConnectionlessSlaveBroadcastChannelMapChangeEvent) << 21;
				num |= EnableBitInfo.EnableBitToValue(enumCollection.InquiryResponseNotificationEvent) << 22;
				return num | (EnableBitInfo.EnableBitToValue(enumCollection.AuthenticatedPayloadTimeoutExpiredEvent) << 23);
			}

			public static string EventMaskPage2ToString(EventMaskPage2EnumCollection enumCollection)
			{
				string text = "";
				text = text + "Physical Link Complete Event: " + EnableBitInfo.EnableBitToString(enumCollection.PhysicalLinkCompleteEvent) + "\r\n";
				text = text + "Channel Selected Event: " + EnableBitInfo.EnableBitToString(enumCollection.ChannelSelectedEvent) + "\r\n";
				text = text + "Disconnection Physical Link Event: " + EnableBitInfo.EnableBitToString(enumCollection.DisconnectionPhysicalLinkEvent) + "\r\n";
				text = text + "Physical Link Loss Early Warning Event: " + EnableBitInfo.EnableBitToString(enumCollection.PhysicalLinkLossEarlyWarningEvent) + "\r\n";
				text = text + "Physical Link Recovery Event: " + EnableBitInfo.EnableBitToString(enumCollection.PhysicalLinkRecoveryEvent) + "\r\n";
				text = text + "Logical Link Complete Event: " + EnableBitInfo.EnableBitToString(enumCollection.LogicalLinkCompleteEvent) + "\r\n";
				text = text + "Disconnection Logical Link Complete Event: " + EnableBitInfo.EnableBitToString(enumCollection.DisconnectionLogicalLinkCompleteEvent) + "\r\n";
				text = text + "Flow Spec Modify Complete Event: " + EnableBitInfo.EnableBitToString(enumCollection.FlowSpecModifyCompleteEvent) + "\r\n";
				text = text + "Number of Completed Data Blocks Event: " + EnableBitInfo.EnableBitToString(enumCollection.NumberOfCompletedDataBlocksEvent) + "\r\n";
				text = text + "AMP Start Test Event: " + EnableBitInfo.EnableBitToString(enumCollection.AmpStartTestEvent) + "\r\n";
				text = text + "AMP Test End Event: " + EnableBitInfo.EnableBitToString(enumCollection.AmpTestEndEvent) + "\r\n";
				text = text + "AMP Receiver Report Event: " + EnableBitInfo.EnableBitToString(enumCollection.AmpReceiverReportEvent) + "\r\n";
				text = text + "Short Range Mode Change Complete Event: " + EnableBitInfo.EnableBitToString(enumCollection.ShortRangeModeChangeCompleteEvent) + "\r\n";
				text = text + "AMP Status Change Event: " + EnableBitInfo.EnableBitToString(enumCollection.AmpStatusChangeEvent) + "\r\n";
				text = text + "Triggered Clock Capture Event: " + EnableBitInfo.EnableBitToString(enumCollection.TriggeredClockCaptureEvent) + "\r\n";
				text = text + "Synchronization Train Complete Event: " + EnableBitInfo.EnableBitToString(enumCollection.SynchronizationTrainCompleteEvent) + "\r\n";
				text = text + "Synchronization Train Received Event: " + EnableBitInfo.EnableBitToString(enumCollection.SynchronizationTrainReceivedEvent) + "\r\n";
				text = text + "Connectionless Slave Broadcast Receive Event: " + EnableBitInfo.EnableBitToString(enumCollection.ConnectionlessSlaveBroadcastReceiveEvent) + "\r\n";
				text = text + "Connectionless Slave Broadcast Timeout Event: " + EnableBitInfo.EnableBitToString(enumCollection.ConnectionlessSlaveBroadcastTimeoutEvent) + "\r\n";
				text = text + "Truncated Page Complete Event: " + EnableBitInfo.EnableBitToString(enumCollection.TruncatedPageCompleteEvent) + "\r\n";
				text = text + "Slave Page Response Timeout Event: " + EnableBitInfo.EnableBitToString(enumCollection.SlavePageResponseTimeoutEvent) + "\r\n";
				text = text + "Connectionless Slave Broadcast Channel Map Change Event: " + EnableBitInfo.EnableBitToString(enumCollection.ConnectionlessSlaveBroadcastChannelMapChangeEvent) + "\r\n";
				text = text + "Inquiry Response Notification Event: " + EnableBitInfo.EnableBitToString(enumCollection.InquiryResponseNotificationEvent) + "\r\n";
				text = text + "Authenticated Payload Timeout Expired Event: " + EnableBitInfo.EnableBitToString(enumCollection.AuthenticatedPayloadTimeoutExpiredEvent) + "\r\n";
				return text.TrimEnd('\r', '\n');
			}

			public static string EventMaskPage2ToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("Bit 0: Physical Link Complete Event");
				stringBuilder.AppendLine("Bit 1: Channel Selected Event");
				stringBuilder.AppendLine("Bit 2: Disconnection Physical Link Event");
				stringBuilder.AppendLine("Bit 3: Physical Link Loss Early Warning Event");
				stringBuilder.AppendLine("Bit 4: Physical Link Recovery Event");
				stringBuilder.AppendLine("Bit 5: Logical Link Complete Event");
				stringBuilder.AppendLine("Bit 6: Disconnection Logical Link Complete Event");
				stringBuilder.AppendLine("Bit 7: Flow Spec Modify Complete Event");
				stringBuilder.AppendLine("Bit 8: Number of Completed Data Blocks Event");
				stringBuilder.AppendLine("Bit 9: AMP Start Test Event");
				stringBuilder.AppendLine("Bit 10: AMP Test End Event");
				stringBuilder.AppendLine("Bit 11: AMP Receiver Report Event");
				stringBuilder.AppendLine("Bit 12: Short Range Mode Change Complete Event");
				stringBuilder.AppendLine("Bit 13: AMP Status Change Event");
				stringBuilder.AppendLine("Bit 14: Triggered Clock Capture Event");
				stringBuilder.AppendLine("Bit 15: Synchronization Train Complete Event");
				stringBuilder.AppendLine("Bit 16: Synchronization Train Received Event");
				stringBuilder.AppendLine("Bit 17: Connectionless Slave Broadcast Receive Event");
				stringBuilder.AppendLine("Bit 18: Connectionless Slave Broadcast Timeout Event");
				stringBuilder.AppendLine("Bit 19: Truncated Page Complete Event");
				stringBuilder.AppendLine("Bit 20: Slave Page Response Timeout Event");
				stringBuilder.AppendLine("Bit 21: Connectionless Slave Broadcast Channel Map Change Event");
				stringBuilder.AppendLine("Bit 22: Inquiry Response Notification Event");
				stringBuilder.AppendLine("Bit 23: Authenticated Payload Timeout Expired Event");
				stringBuilder.AppendLine("Bits 63-24: Reserved for future use");
				return stringBuilder.ToString();
			}
		}

		private ulong _EventMaskPage2;

		public ulong EventMaskPage2
		{
			get
			{
				return _EventMaskPage2;
			}
			set
			{
				_EventMaskPage2 = value;
			}
		}

		public EventMaskPage2EnumCollection GetEventMaskPage2AsEventMaskPage2EnumCollection()
		{
			return EventMaskPage2Info.ValueToEventMaskPage2(_EventMaskPage2);
		}

		public void SetEventMaskPage2AsEventMaskPage2EnumCollection(EventMaskPage2EnumCollection enumCollection)
		{
			EventMaskPage2 = EventMaskPage2Info.EventMaskPage2ToValue(enumCollection);
		}
	}

	private const uint _Opcode = 3171u;

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

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

	public uint Opcode => 3171u;

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

	public UserFieldsWrapper UserFields => _UserFields;

	public override void SetDefaultValues()
	{
		UserFields.EventMaskPage2 = 0uL;
	}

	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;
		}
		UserFields.EventMaskPage2 = bitBuilder.RemoveBitsAsUlongLittleEndian(64);
		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.AddBitsAsUlongLittleEndian(UserFields.EventMaskPage2, 64);
		_PayloadLength = (uint)((bitBuilder.GetNumberOfBits() - numberOfBits - 8) / 8);
		if ((bitBuilder.GetNumberOfBits() - numberOfBits - 8) % 8 != 0)
		{
			_PayloadLength++;
		}
		bitBuilder.ChangeBitsAsUint(numberOfBits, _PayloadLength, 8);
		return bitBuilder.ToString();
	}
}
