using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LePathLossThresholdEventInfo : PacketInfoBase
{
	public override string Name => "Le Path Loss Threshold Event";

	public override string DisplayGroup => "LE Controller";

	public LePathLossThresholdEventInfo(LePathLossThresholdEvent packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LePathLossThresholdEvent lePathLossThresholdEvent = (LePathLossThresholdEvent)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Subevent_Code", "Subevent code for the LE_Path_Loss_Threshold event", 8, FormatValue(lePathLossThresholdEvent.UserFields.SubeventCode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Connection Handle", "Handle of LE connection receiving power report", 16, FormatValue(lePathLossThresholdEvent.UserFields.ConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Current Path Loss", "Current path loss (always zero or positive). Units: dB\r\n\r\n" + LePathLossThresholdEvent.UserFieldsWrapper.CurrentPathLossInfo.CurrentPathLossToDescription(), 8, FormatValue(lePathLossThresholdEvent.UserFields.CurrentPathLoss, 8), LePathLossThresholdEvent.UserFieldsWrapper.CurrentPathLossInfo.CurrentPathLossToString(LePathLossThresholdEvent.UserFieldsWrapper.CurrentPathLossInfo.ValueToCurrentPathLoss(lePathLossThresholdEvent.UserFields.CurrentPathLoss)), "00", "FF", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Zone_Entered", "Indicates which zone was entered.\r\n\r\n" + LePathLossThresholdEvent.UserFieldsWrapper.ZoneEnteredInfo.ZoneEnteredToDescription(), 8, FormatValue(lePathLossThresholdEvent.UserFields.ZoneEntered, 8), LePathLossThresholdEvent.UserFieldsWrapper.ZoneEnteredInfo.ZoneEnteredToString(LePathLossThresholdEvent.UserFieldsWrapper.ZoneEnteredInfo.ValueToZoneEntered(lePathLossThresholdEvent.UserFields.ZoneEntered)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LePathLossThresholdEvent lePathLossThresholdEvent = (LePathLossThresholdEvent)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubeventCode");
		}
		if (index == ++num)
		{
			lePathLossThresholdEvent.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			lePathLossThresholdEvent.UserFields.CurrentPathLoss = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			lePathLossThresholdEvent.UserFields.ZoneEntered = Convert.ToUInt32(value, 16);
		}
	}
}
