using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class PeriodicInquiryModeInfo : PacketInfoBase
{
	public override string Name => "Periodic Inquiry Mode";

	public override string DisplayGroup => "Link Control";

	public PeriodicInquiryModeInfo(PeriodicInquiryMode packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		PeriodicInquiryMode periodicInquiryMode = (PeriodicInquiryMode)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Max Period Length", "Maximum amount of time specified between consecutive inquiries (N * 1.28 sec).", 16, FormatValue(periodicInquiryMode.UserFields.MaxPeriodLength, 16), "", "0003", "FFFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Min Period Length", "Minimum amount of time specified between consecutive inquiries (N * 1.28 sec).", 16, FormatValue(periodicInquiryMode.UserFields.MinPeriodLength, 16), "", "0002", "FFFE", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("LAP", "LAP from which the inquiry access code should be derived when the inquiry procedure is made; see Bluetooth Assigned Numbers.", 24, FormatValue(periodicInquiryMode.UserFields.Lap, 24), "", "9E8B00", "9E8B3F", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Inquiry Length", "Maximum amount of time specified before the Inquiry is halted (N * 1.28 sec).", 8, FormatValue(periodicInquiryMode.UserFields.InquiryLength, 8), "", "01", "30", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Num Responses", PeriodicInquiryMode.UserFieldsWrapper.NumResponsesInfo.NumResponsesToDescription(), 8, FormatValue(periodicInquiryMode.UserFields.NumResponses, 8), PeriodicInquiryMode.UserFieldsWrapper.NumResponsesInfo.NumResponsesToString(PeriodicInquiryMode.UserFieldsWrapper.NumResponsesInfo.ValueToNumResponses(periodicInquiryMode.UserFields.NumResponses)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		PeriodicInquiryMode periodicInquiryMode = (PeriodicInquiryMode)packet;
		int num = -1;
		if (index == ++num)
		{
			periodicInquiryMode.UserFields.MaxPeriodLength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			periodicInquiryMode.UserFields.MinPeriodLength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			periodicInquiryMode.UserFields.Lap = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			periodicInquiryMode.UserFields.InquiryLength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			periodicInquiryMode.UserFields.NumResponses = Convert.ToUInt32(value, 16);
		}
	}
}
