using System;
using QCRPG.Framework;

namespace QCRPG.TSL.ZigBee.Packets;

public class PlatformWakeEventInfo : PacketInfoBase
{
	public override string Name => "Platform Wake Event";

	public override string DisplayGroup => "MLME Confirmation Packets";

	public PlatformWakeEventInfo(PlatformWakeEvent packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		PlatformWakeEvent platformWakeEvent = (PlatformWakeEvent)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("PacketLength", "", 32, FormatValue(platformWakeEvent.UserFields.Packetlength, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("CmdID", "", 8, FormatValue(platformWakeEvent.UserFields.Cmdid, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("WakeReason", PlatformWakeEvent.UserFieldsWrapper.WakereasonInfo.WakereasonToDescription(), 8, FormatValue(platformWakeEvent.UserFields.Wakereason, 8), PlatformWakeEvent.UserFieldsWrapper.WakereasonInfo.WakereasonToString(PlatformWakeEvent.UserFieldsWrapper.WakereasonInfo.ValueToWakereason(platformWakeEvent.UserFields.Wakereason)), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		PlatformWakeEvent platformWakeEvent = (PlatformWakeEvent)packet;
		int num = -1;
		if (index == ++num)
		{
			platformWakeEvent.UserFields.Packetlength = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field Cmdid");
		}
		if (index == ++num)
		{
			platformWakeEvent.UserFields.Wakereason = Convert.ToUInt32(value, 16);
		}
	}
}
