using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeTransmitPowerReportingEventInfo : PacketInfoBase
{
	public override string Name => "Le Transmit Power Reporting Event";

	public override string DisplayGroup => "LE Controller";

	public LeTransmitPowerReportingEventInfo(LeTransmitPowerReportingEvent packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeTransmitPowerReportingEvent leTransmitPowerReportingEvent = (LeTransmitPowerReportingEvent)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Subevent_Code", "Subevent code for the LE_Transmit_Power_Reporting event", 8, FormatValue(leTransmitPowerReportingEvent.UserFields.SubeventCode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(leTransmitPowerReportingEvent.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(leTransmitPowerReportingEvent.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Connection Handle", "Handle of LE connection receiving power report", 16, FormatValue(leTransmitPowerReportingEvent.UserFields.ConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Reason", "Why the event was sent and which device transmit power level is being reported.\r\n\r\n" + LeTransmitPowerReportingEvent.UserFieldsWrapper.ReasonInfo.ReasonToDescription(), 8, FormatValue(leTransmitPowerReportingEvent.UserFields.Reason, 8), LeTransmitPowerReportingEvent.UserFieldsWrapper.ReasonInfo.ReasonToString(LeTransmitPowerReportingEvent.UserFieldsWrapper.ReasonInfo.ValueToReason(leTransmitPowerReportingEvent.UserFields.Reason)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("phy", "The PHY involved.\r\n\r\n" + LeTransmitPowerReportingEvent.UserFieldsWrapper.PhyInfo.PhyToDescription(), 8, FormatValue(leTransmitPowerReportingEvent.UserFields.Phy, 8), LeTransmitPowerReportingEvent.UserFieldsWrapper.PhyInfo.PhyToString(LeTransmitPowerReportingEvent.UserFieldsWrapper.PhyInfo.ValueToPhy(leTransmitPowerReportingEvent.UserFields.Phy)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Transmit Power Level", "Transmit power level. Range: -127 to 20. Units: dBm\r\n\r\n" + LeTransmitPowerReportingEvent.UserFieldsWrapper.TransmitPowerLevelInfo.TransmitPowerLevelToDescription(), 8, FormatValue(leTransmitPowerReportingEvent.UserFields.TransmitPowerLevel, 8), LeTransmitPowerReportingEvent.UserFieldsWrapper.TransmitPowerLevelInfo.TransmitPowerLevelToString(LeTransmitPowerReportingEvent.UserFieldsWrapper.TransmitPowerLevelInfo.ValueToTransmitPowerLevel(leTransmitPowerReportingEvent.UserFields.TransmitPowerLevel)), "00", "7F", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Transmit Power Level Flag", "The transmit power level that is being reported has reached its minimum and/or maximum level.\r\n\r\n" + LeTransmitPowerReportingEvent.UserFieldsWrapper.TransmitPowerLevelFlagInfo.TransmitPowerLevelFlagToDescription(), 8, FormatValue(leTransmitPowerReportingEvent.UserFields.TransmitPowerLevelFlag, 8), LeTransmitPowerReportingEvent.UserFieldsWrapper.TransmitPowerLevelFlagInfo.TransmitPowerLevelFlagToString(LeTransmitPowerReportingEvent.UserFieldsWrapper.TransmitPowerLevelFlagInfo.ValueToTransmitPowerLevelFlag(leTransmitPowerReportingEvent.UserFields.TransmitPowerLevelFlag)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Delta", "Change in transmit power level (positive indicates increased power, negative indicates decreased power, zero indicates unchanged). Units: dBm\r\n\r\n" + LeTransmitPowerReportingEvent.UserFieldsWrapper.DeltaInfo.DeltaToDescription(), 8, FormatValue(leTransmitPowerReportingEvent.UserFields.Delta, 8), LeTransmitPowerReportingEvent.UserFieldsWrapper.DeltaInfo.DeltaToString(LeTransmitPowerReportingEvent.UserFieldsWrapper.DeltaInfo.ValueToDelta(leTransmitPowerReportingEvent.UserFields.Delta)), "00", "7F", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeTransmitPowerReportingEvent leTransmitPowerReportingEvent = (LeTransmitPowerReportingEvent)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubeventCode");
		}
		if (index == ++num)
		{
			leTransmitPowerReportingEvent.UserFields.Status = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leTransmitPowerReportingEvent.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leTransmitPowerReportingEvent.UserFields.Reason = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leTransmitPowerReportingEvent.UserFields.Phy = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leTransmitPowerReportingEvent.UserFields.TransmitPowerLevel = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leTransmitPowerReportingEvent.UserFields.TransmitPowerLevelFlag = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leTransmitPowerReportingEvent.UserFields.Delta = Convert.ToUInt32(value, 16);
		}
	}
}
