using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class HeadlessSetScanModeInfo : PacketInfoBase
{
	public override string Name => "Headless Set Scan Mode";

	public override string DisplayGroup => "Vendor Specific";

	public HeadlessSetScanModeInfo(HeadlessSetScanMode packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		HeadlessSetScanMode headlessSetScanMode = (HeadlessSetScanMode)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Sub OpCode", "HCI_VSC_HEADLESS_SET_SCAN_MODE", 8, FormatValue(headlessSetScanMode.UserFields.SubOpcode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Page Scan Interval", "Page scan interval in the headless mode", 16, FormatValue(headlessSetScanMode.UserFields.PageScanInterval, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Page Scan Window size", "Window in the headless mode", 16, FormatValue(headlessSetScanMode.UserFields.PageScanWindowSize, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Page Scan Mode", "Scan mode in the headless mode", 8, FormatValue(headlessSetScanMode.UserFields.PageScanMode, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		HeadlessSetScanMode headlessSetScanMode = (HeadlessSetScanMode)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubOpcode");
		}
		if (index == ++num)
		{
			headlessSetScanMode.UserFields.PageScanInterval = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			headlessSetScanMode.UserFields.PageScanWindowSize = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			headlessSetScanMode.UserFields.PageScanMode = Convert.ToUInt32(value, 16);
		}
	}
}
