using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class WriteCurrentIacLapInfo : PacketInfoBase
{
	public override string Name => "Write Current Iac Lap";

	public override string DisplayGroup => "Host Control and Baseband";

	public WriteCurrentIacLapInfo(WriteCurrentIacLap packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		WriteCurrentIacLap writeCurrentIacLap = (WriteCurrentIacLap)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Number Current IAC", "", 8, FormatValue(writeCurrentIacLap.UserFields.NumberCurrentIac, 8), "", "01", "40", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < writeCurrentIacLap.UserFields.ParameterList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("IAC LAP[" + i + "]", "LAP(s) used to create IAC which is currently in use by the local BR/EDR Controller to simultaneously listen for during an Inquiry Scan", 24, FormatValue(writeCurrentIacLap.UserFields.ParameterList[i].IacLap, 24), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		WriteCurrentIacLap writeCurrentIacLap = (WriteCurrentIacLap)packet;
		int num = -1;
		if (index == ++num)
		{
			writeCurrentIacLap.UserFields.NumberCurrentIac = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < writeCurrentIacLap.UserFields.ParameterList.Count; i++)
		{
			if (index == ++num)
			{
				writeCurrentIacLap.UserFields.ParameterList[i].IacLap = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
