using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FMHCI.Packets;

public class DemodInputDataInfo : PacketInfoBase
{
	public override string Name => "Demod Input Data";

	public override string DisplayGroup => "Events";

	public DemodInputDataInfo(DemodInputData packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		DemodInputData demodInputData = (DemodInputData)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(demodInputData.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(demodInputData.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Buffer Head", "Relative position of the last received sample w.r.t starting of the Demod Input Data buffer in dWords", 16, FormatValue(demodInputData.UserFields.BufferHead, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Length", "Number of bytes of demod input data", 8, FormatValue(demodInputData.UserFields.Length, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Demod Input Data", "Raw bytes of demod input data", demodInputData.UserFields.DemodInputDataList.Count * 8, FormatValue(demodInputData.UserFields.DemodInputDataList, demodInputData.UserFields.DemodInputDataList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		DemodInputData demodInputData = (DemodInputData)packet;
		int num = -1;
		if (index == ++num)
		{
			demodInputData.UserFields.Status = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			demodInputData.UserFields.BufferHead = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			demodInputData.UserFields.Length = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, demodInputData.UserFields.DemodInputDataList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				demodInputData.UserFields.DemodInputDataList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
