using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FM.Packets;

public class ReadRdsProgramService : PacketBase
{
	public class UserFieldsWrapper
	{
		private const uint _RegisterAddress = 31u;

		private const uint _XfrMode = 1u;

		public uint RegisterAddress => 31u;

		public uint XfrMode => 1u;

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

		public XfrModeMapEnum GetXfrModeAsXfrModeMapEnum()
		{
			return XfrModeMapInfo.ValueToXfrModeMap(1u);
		}
	}

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

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

	public UserFieldsWrapper UserFields => _UserFields;

	protected override bool FromBitBuilder(ref BitBuilder bitBuilder)
	{
		if (bitBuilder.RemoveBitsAsUint(8) != UserFields.RegisterAddress)
		{
			return false;
		}
		if (bitBuilder.RemoveBitsAsUint(8) != UserFields.XfrMode)
		{
			return false;
		}
		if (bitBuilder.GetNumberOfBits() > 7)
		{
			return false;
		}
		return true;
	}

	public override string ToBitString()
	{
		BitBuilder bitBuilder = new BitBuilder();
		bitBuilder.AddBitsAsUint(UserFields.RegisterAddress, 8);
		bitBuilder.AddBitsAsUint(UserFields.XfrMode, 8);
		return bitBuilder.ToString();
	}
}
