using System;
using QCRPG.Framework;

namespace QCRPG.TSL.ZigBee.Packets;

public class VsDutTxRawInfo : PacketInfoBase
{
	public override string Name => "Vs Dut Tx Raw";

	public override string DisplayGroup => "Vendor Specific Packets";

	public VsDutTxRawInfo(VsDutTxRaw packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		VsDutTxRaw vsDutTxRaw = (VsDutTxRaw)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Flags", VsDutTxRaw.UserFieldsWrapper.FlagsInfo.FlagsToDescription(), 32, FormatValue(vsDutTxRaw.UserFields.Flags, 32), VsDutTxRaw.UserFieldsWrapper.FlagsInfo.FlagsToString(VsDutTxRaw.UserFieldsWrapper.FlagsInfo.ValueToFlags(vsDutTxRaw.UserFields.Flags)), "00000000", "00000003", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Page", "Page that for the test", 8, FormatValue(vsDutTxRaw.UserFields.Page, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Channel", "Range (0B(11)-0x1A/26(Decimal))", 8, FormatValue(vsDutTxRaw.UserFields.Channel, 8), "", "0B", "1A", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.DecimalInteger));
		fieldInfoList.Add(new PacketFieldInfo("Power", "Range (0-0xF/15(Decimal))", 8, FormatValue(vsDutTxRaw.UserFields.Power, 8), "", "00", "0F", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.DecimalInteger));
		fieldInfoList.Add(new PacketFieldInfo("PayloadLength", "Length of the payload data in each packet", 16, FormatValue(vsDutTxRaw.UserFields.Payloadlength, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Payload", "", vsDutTxRaw.UserFields.PayloadList.Count * 8, FormatValue(vsDutTxRaw.UserFields.PayloadList, vsDutTxRaw.UserFields.PayloadList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		VsDutTxRaw vsDutTxRaw = (VsDutTxRaw)packet;
		int num = -1;
		if (index == ++num)
		{
			vsDutTxRaw.UserFields.Flags = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			vsDutTxRaw.UserFields.Page = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			vsDutTxRaw.UserFields.Channel = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			vsDutTxRaw.UserFields.Power = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			vsDutTxRaw.UserFields.Payloadlength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, vsDutTxRaw.UserFields.PayloadList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				vsDutTxRaw.UserFields.PayloadList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
