using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class TriggeredClockCaptureInfo : PacketInfoBase
{
	public override string Name => "Triggered Clock Capture";

	public override string DisplayGroup => "Status Parameters";

	public TriggeredClockCaptureInfo(TriggeredClockCapture packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		TriggeredClockCapture triggeredClockCapture = (TriggeredClockCapture)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Connection_Handle", "Connection Handle to be used to identify a connection. Range: 0x0000 - 0x0EFF (0x0F00 - 0x0FFF Reserved for future use).", 16, FormatValue(triggeredClockCapture.UserFields.ConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Which_Clock", TriggeredClockCapture.UserFieldsWrapper.WhichClockInfo.WhichClockToDescription(), 8, FormatValue(triggeredClockCapture.UserFields.WhichClock, 8), TriggeredClockCapture.UserFieldsWrapper.WhichClockInfo.WhichClockToString(TriggeredClockCapture.UserFieldsWrapper.WhichClockInfo.ValueToWhichClock(triggeredClockCapture.UserFields.WhichClock)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Clock", "Bluetooth clock of the device requested with bits 1 and 0 set to 0b.", 32, FormatValue(triggeredClockCapture.UserFields.Clock, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Slot_Offset", "Number of microseconds from the selected clock attaining the value Clock until the triggering event. Range: 0 to 1249.", 16, FormatValue(triggeredClockCapture.UserFields.SlotOffset, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		TriggeredClockCapture triggeredClockCapture = (TriggeredClockCapture)packet;
		int num = -1;
		if (index == ++num)
		{
			triggeredClockCapture.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			triggeredClockCapture.UserFields.WhichClock = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			triggeredClockCapture.UserFields.Clock = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			triggeredClockCapture.UserFields.SlotOffset = Convert.ToUInt32(value, 16);
		}
	}
}
