using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FM.Packets;

public class InterruptMask : PacketBase
{
	public class UserFieldsWrapper
	{
		private const uint _RegisterAddress = 0u;

		private const uint _Undefined = 0u;

		private uint _Audio;

		private uint _Sync;

		private uint _Interference;

		private uint _Signal;

		private uint _ScanNext;

		private uint _Search;

		private uint _Tune;

		private uint _Ready;

		private uint _TxRdsDone;

		private uint _TxRds;

		private uint _RdsAfListAvailable;

		private uint _RdsRadioTextAvailable;

		private uint _RdsProgramService;

		private uint _ProgramIdMatch;

		private uint _BlockBMatch;

		private uint _RdsDataAvailable;

		private uint _Error;

		private uint _DynamicRdsProcessingComplete;

		private uint _DataTransferComplete;

		public uint RegisterAddress => 0u;

		public uint Audio
		{
			get
			{
				return _Audio;
			}
			set
			{
				if (value > 1)
				{
					throw new Exception("Maximum possible value for Audio is 0x1");
				}
				_Audio = value;
			}
		}

		public uint Sync
		{
			get
			{
				return _Sync;
			}
			set
			{
				if (value > 1)
				{
					throw new Exception("Maximum possible value for Sync is 0x1");
				}
				_Sync = value;
			}
		}

		public uint Interference
		{
			get
			{
				return _Interference;
			}
			set
			{
				if (value > 1)
				{
					throw new Exception("Maximum possible value for Interference is 0x1");
				}
				_Interference = value;
			}
		}

		public uint Signal
		{
			get
			{
				return _Signal;
			}
			set
			{
				if (value > 1)
				{
					throw new Exception("Maximum possible value for Signal is 0x1");
				}
				_Signal = value;
			}
		}

		public uint ScanNext
		{
			get
			{
				return _ScanNext;
			}
			set
			{
				if (value > 1)
				{
					throw new Exception("Maximum possible value for ScanNext is 0x1");
				}
				_ScanNext = value;
			}
		}

		public uint Search
		{
			get
			{
				return _Search;
			}
			set
			{
				if (value > 1)
				{
					throw new Exception("Maximum possible value for Search is 0x1");
				}
				_Search = value;
			}
		}

		public uint Tune
		{
			get
			{
				return _Tune;
			}
			set
			{
				if (value > 1)
				{
					throw new Exception("Maximum possible value for Tune is 0x1");
				}
				_Tune = value;
			}
		}

		public uint Ready
		{
			get
			{
				return _Ready;
			}
			set
			{
				if (value > 1)
				{
					throw new Exception("Maximum possible value for Ready is 0x1");
				}
				_Ready = value;
			}
		}

		public uint TxRdsDone
		{
			get
			{
				return _TxRdsDone;
			}
			set
			{
				if (value > 1)
				{
					throw new Exception("Maximum possible value for TxRdsDone is 0x1");
				}
				_TxRdsDone = value;
			}
		}

		public uint TxRds
		{
			get
			{
				return _TxRds;
			}
			set
			{
				if (value > 1)
				{
					throw new Exception("Maximum possible value for TxRds is 0x1");
				}
				_TxRds = value;
			}
		}

		public uint RdsAfListAvailable
		{
			get
			{
				return _RdsAfListAvailable;
			}
			set
			{
				if (value > 1)
				{
					throw new Exception("Maximum possible value for RdsAfListAvailable is 0x1");
				}
				_RdsAfListAvailable = value;
			}
		}

		public uint RdsRadioTextAvailable
		{
			get
			{
				return _RdsRadioTextAvailable;
			}
			set
			{
				if (value > 1)
				{
					throw new Exception("Maximum possible value for RdsRadioTextAvailable is 0x1");
				}
				_RdsRadioTextAvailable = value;
			}
		}

		public uint RdsProgramService
		{
			get
			{
				return _RdsProgramService;
			}
			set
			{
				if (value > 1)
				{
					throw new Exception("Maximum possible value for RdsProgramService is 0x1");
				}
				_RdsProgramService = value;
			}
		}

		public uint ProgramIdMatch
		{
			get
			{
				return _ProgramIdMatch;
			}
			set
			{
				if (value > 1)
				{
					throw new Exception("Maximum possible value for ProgramIdMatch is 0x1");
				}
				_ProgramIdMatch = value;
			}
		}

		public uint BlockBMatch
		{
			get
			{
				return _BlockBMatch;
			}
			set
			{
				if (value > 1)
				{
					throw new Exception("Maximum possible value for BlockBMatch is 0x1");
				}
				_BlockBMatch = value;
			}
		}

		public uint RdsDataAvailable
		{
			get
			{
				return _RdsDataAvailable;
			}
			set
			{
				if (value > 1)
				{
					throw new Exception("Maximum possible value for RdsDataAvailable is 0x1");
				}
				_RdsDataAvailable = value;
			}
		}

		public uint Error
		{
			get
			{
				return _Error;
			}
			set
			{
				if (value > 1)
				{
					throw new Exception("Maximum possible value for Error is 0x1");
				}
				_Error = value;
			}
		}

		public uint Undefined => 0u;

		public uint DynamicRdsProcessingComplete
		{
			get
			{
				return _DynamicRdsProcessingComplete;
			}
			set
			{
				if (value > 1)
				{
					throw new Exception("Maximum possible value for DynamicRdsProcessingComplete is 0x1");
				}
				_DynamicRdsProcessingComplete = value;
			}
		}

		public uint DataTransferComplete
		{
			get
			{
				return _DataTransferComplete;
			}
			set
			{
				if (value > 1)
				{
					throw new Exception("Maximum possible value for DataTransferComplete is 0x1");
				}
				_DataTransferComplete = value;
			}
		}

		public RegisterMapEnum GetRegisterAddressAsRegisterMapEnum()
		{
			return RegisterMapInfo.ValueToRegisterMap(0u);
		}
	}

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

	private PacketInfoBase info;

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

	public UserFieldsWrapper UserFields => _UserFields;

	public override void SetDefaultValues()
	{
		UserFields.Audio = 1u;
		UserFields.Sync = 1u;
		UserFields.Interference = 1u;
		UserFields.Signal = 1u;
		UserFields.ScanNext = 1u;
		UserFields.Search = 1u;
		UserFields.Tune = 1u;
		UserFields.Ready = 1u;
		UserFields.TxRdsDone = 1u;
		UserFields.TxRds = 1u;
		UserFields.RdsAfListAvailable = 1u;
		UserFields.RdsRadioTextAvailable = 1u;
		UserFields.RdsProgramService = 1u;
		UserFields.ProgramIdMatch = 1u;
		UserFields.BlockBMatch = 1u;
		UserFields.RdsDataAvailable = 1u;
		UserFields.Error = 1u;
		UserFields.DynamicRdsProcessingComplete = 1u;
		UserFields.DataTransferComplete = 1u;
	}

	protected override bool FromBitBuilder(ref BitBuilder bitBuilder)
	{
		if (bitBuilder.RemoveBitsAsUint(8) != UserFields.RegisterAddress)
		{
			return false;
		}
		UserFields.Audio = bitBuilder.RemoveBitsAsUint(1);
		UserFields.Sync = bitBuilder.RemoveBitsAsUint(1);
		UserFields.Interference = bitBuilder.RemoveBitsAsUint(1);
		UserFields.Signal = bitBuilder.RemoveBitsAsUint(1);
		UserFields.ScanNext = bitBuilder.RemoveBitsAsUint(1);
		UserFields.Search = bitBuilder.RemoveBitsAsUint(1);
		UserFields.Tune = bitBuilder.RemoveBitsAsUint(1);
		UserFields.Ready = bitBuilder.RemoveBitsAsUint(1);
		UserFields.TxRdsDone = bitBuilder.RemoveBitsAsUint(1);
		UserFields.TxRds = bitBuilder.RemoveBitsAsUint(1);
		UserFields.RdsAfListAvailable = bitBuilder.RemoveBitsAsUint(1);
		UserFields.RdsRadioTextAvailable = bitBuilder.RemoveBitsAsUint(1);
		UserFields.RdsProgramService = bitBuilder.RemoveBitsAsUint(1);
		UserFields.ProgramIdMatch = bitBuilder.RemoveBitsAsUint(1);
		UserFields.BlockBMatch = bitBuilder.RemoveBitsAsUint(1);
		UserFields.RdsDataAvailable = bitBuilder.RemoveBitsAsUint(1);
		UserFields.Error = bitBuilder.RemoveBitsAsUint(1);
		if (bitBuilder.RemoveBitsAsUint(5) != UserFields.Undefined)
		{
			return false;
		}
		UserFields.DynamicRdsProcessingComplete = bitBuilder.RemoveBitsAsUint(1);
		UserFields.DataTransferComplete = bitBuilder.RemoveBitsAsUint(1);
		if (bitBuilder.GetNumberOfBits() > 7)
		{
			return false;
		}
		return true;
	}

	public override string ToBitString()
	{
		BitBuilder bitBuilder = new BitBuilder();
		bitBuilder.AddBitsAsUint(UserFields.RegisterAddress, 8);
		bitBuilder.AddBitsAsUint(UserFields.Audio, 1);
		bitBuilder.AddBitsAsUint(UserFields.Sync, 1);
		bitBuilder.AddBitsAsUint(UserFields.Interference, 1);
		bitBuilder.AddBitsAsUint(UserFields.Signal, 1);
		bitBuilder.AddBitsAsUint(UserFields.ScanNext, 1);
		bitBuilder.AddBitsAsUint(UserFields.Search, 1);
		bitBuilder.AddBitsAsUint(UserFields.Tune, 1);
		bitBuilder.AddBitsAsUint(UserFields.Ready, 1);
		bitBuilder.AddBitsAsUint(UserFields.TxRdsDone, 1);
		bitBuilder.AddBitsAsUint(UserFields.TxRds, 1);
		bitBuilder.AddBitsAsUint(UserFields.RdsAfListAvailable, 1);
		bitBuilder.AddBitsAsUint(UserFields.RdsRadioTextAvailable, 1);
		bitBuilder.AddBitsAsUint(UserFields.RdsProgramService, 1);
		bitBuilder.AddBitsAsUint(UserFields.ProgramIdMatch, 1);
		bitBuilder.AddBitsAsUint(UserFields.BlockBMatch, 1);
		bitBuilder.AddBitsAsUint(UserFields.RdsDataAvailable, 1);
		bitBuilder.AddBitsAsUint(UserFields.Error, 1);
		bitBuilder.AddBitsAsUint(UserFields.Undefined, 5);
		bitBuilder.AddBitsAsUint(UserFields.DynamicRdsProcessingComplete, 1);
		bitBuilder.AddBitsAsUint(UserFields.DataTransferComplete, 1);
		return bitBuilder.ToString();
	}
}
