using System;
using QCRPG.Framework;

namespace QCRPG.TSL.ZigBee.Packets;

public class MlmeStartInfo : PacketInfoBase
{
	public override string Name => "Mlme Start";

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

	public MlmeStartInfo(MlmeStart packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		MlmeStart mlmeStart = (MlmeStart)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("PANId", "The PAN identifier to be used by the device", 16, FormatValue(mlmeStart.UserFields.Panid, 16), "", "0000", "0xFFFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("LogicalChannel", "The logical channel on which to start using the new superframe configuration.", 8, FormatValue(mlmeStart.UserFields.Logicalchannel, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("ChannelPage", "The channel page on which to begin using the new superframe configuration.", 8, FormatValue(mlmeStart.UserFields.Channelpage, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("StartTime", "The time at which to begin transmitting beacons. If this parameter is equal to 0x000000, beacon transmissions will begin immediately. Otherwise, the specified time is relative to the received beacon of the coordinator with which the device synchronizes. This parameter is ignored if either the BeaconOrder parameter has a value of 15 or the PANCoordinator parameter is TRUE. The time is specified in symbols and is rounded to a backoff slot boundary. This is a 24-bit value, and the precision of this value shall be a minimum of 20 bits, with the lowest 4 bits being the least significant.", 32, FormatValue(mlmeStart.UserFields.Starttime, 32), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("BeaconOrder", "How often the beacon is to be transmitted. A value of 15 indicates that the coordinator will not transmit periodic beacons.", 8, FormatValue(mlmeStart.UserFields.Beaconorder, 8), "", "00", "15", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("SuperframeOrder", "The length of the active portion of the superframe, including the beacon frame. If the BeaconOrder parameter (BO) has a value of 15, this parameter is ignored.", 8, FormatValue(mlmeStart.UserFields.Superframeorder, 8), "", "00", "15", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("PANCoordinator", "If this value is TRUE, the device will become the PAN coordinator of a new PAN. If this value is FALSE, the device will begin using a new superframe configuration on the PAN with which it is associated.", 8, FormatValue(mlmeStart.UserFields.Pancoordinator, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("BatteryLifeExtension", "If this value is TRUE, the receiver of the beaconing device is disabled macBattLifeExtPeriods full backoff periods after the interframe spacing (IFS) period following the beacon frame. If this value is FALSE, the receiver of the beaconing device remains enabled for the entire CAP. This parameter is ignored if the BeaconOrder parameter has a value of 15.", 8, FormatValue(mlmeStart.UserFields.Batterylifeextension, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("CoordRealignment", "TRUE if a coordinator realignment command is to be transmitted prior to changing the superframe configuration or FALSE otherwise.", 8, FormatValue(mlmeStart.UserFields.Coordrealignment, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("CoordRealignSecurityLevel", "The security level to be used for coordinator realignment command frames", 8, FormatValue(mlmeStart.UserFields.Coordrealignsecuritylevel, 8), "", "00", "07", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("CoordRealignKeyIdMode", "The mode used to identify the key to be used. This parameter is ignored if the CoordRealignSecurityLevel parameter is set to 0x00.", 8, FormatValue(mlmeStart.UserFields.Coordrealignkeyidmode, 8), "", "00", "03", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("CoordRealignKeySource", "The originator of the key to be used. This parameter is ignored if the CoordRealignKeyId-Mode parameter is ignored or set to 0x00.", 64, FormatValue(mlmeStart.UserFields.Coordrealignkeysource, 64), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("CoordRealignKeyIndex", "The index of the key to be used. This parameter is ignored if the CoordRealignKeyIdMode parameter is ignored or set to 0x00.", 8, FormatValue(mlmeStart.UserFields.Coordrealignkeyindex, 8), "", "01", "FF", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("BeaconSecurityLevel", "The security level to be used for beacon frames, range (0-7)", 8, FormatValue(mlmeStart.UserFields.Beaconsecuritylevel, 8), "", "00", "07", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("BeaconKeyIdMode", "The mode used to identify the key to be used, range (0-3). This parameter is ignored if the BeaconSecurityLevel parameter is set to 0x00.", 8, FormatValue(mlmeStart.UserFields.Beaconkeyidmode, 8), "", "00", "03", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("BeaconKeySource", "The originator of the key to be used. This parameter is ignored if the BeaconKeyIdMode parameter is ignored or set to 0x00.", 64, FormatValue(mlmeStart.UserFields.Beaconkeysource, 64), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("BeaconKeyIndex", "The index of the key to be used, range (01-FF). This parameter is ignored if the BeaconKeyIdMode parameter is ignored or set to 0x00.", 8, FormatValue(mlmeStart.UserFields.Beaconkeyindex, 8), "", "01", "FF", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		MlmeStart mlmeStart = (MlmeStart)packet;
		int num = -1;
		if (index == ++num)
		{
			mlmeStart.UserFields.Panid = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeStart.UserFields.Logicalchannel = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeStart.UserFields.Channelpage = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeStart.UserFields.Starttime = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeStart.UserFields.Beaconorder = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeStart.UserFields.Superframeorder = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeStart.UserFields.Pancoordinator = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeStart.UserFields.Batterylifeextension = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeStart.UserFields.Coordrealignment = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeStart.UserFields.Coordrealignsecuritylevel = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeStart.UserFields.Coordrealignkeyidmode = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeStart.UserFields.Coordrealignkeysource = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			mlmeStart.UserFields.Coordrealignkeyindex = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeStart.UserFields.Beaconsecuritylevel = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeStart.UserFields.Beaconkeyidmode = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mlmeStart.UserFields.Beaconkeysource = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			mlmeStart.UserFields.Beaconkeyindex = Convert.ToUInt32(value, 16);
		}
	}
}
