using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class OtaQlmpCtrlPduInfo : PacketInfoBase
{
	public override string Name => "Ota Qlmp Ctrl Pdu";

	public override string DisplayGroup => "Enhanced Logging";

	public OtaQlmpCtrlPduInfo(OtaQlmpCtrlPdu packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		OtaQlmpCtrlPdu otaQlmpCtrlPdu = (OtaQlmpCtrlPdu)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Seq_Num", "", 8, FormatValue(otaQlmpCtrlPdu.UserFields.SeqNum, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Logs_Lost_Drop", "", 8, FormatValue(otaQlmpCtrlPdu.UserFields.LogsLostDrop, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Prod_ID", "", 8, FormatValue(otaQlmpCtrlPdu.UserFields.ProdId, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Log_Id", OtaQlmpCtrlPdu.UserFieldsWrapper.LogIdInfo.LogIdToDescription(), 16, FormatValue(otaQlmpCtrlPdu.UserFields.LogId, 16), OtaQlmpCtrlPdu.UserFieldsWrapper.LogIdInfo.LogIdToString(OtaQlmpCtrlPdu.UserFieldsWrapper.LogIdInfo.ValueToLogId(otaQlmpCtrlPdu.UserFields.LogId)), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Log_Format_Level", "", 8, FormatValue(otaQlmpCtrlPdu.UserFields.LogFormatLevel, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Timestamp", "", 32, FormatValue(otaQlmpCtrlPdu.UserFields.Timestamp, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Handle", "", 8, FormatValue(otaQlmpCtrlPdu.UserFields.Handle, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Minor_Type", "", 8, FormatValue(otaQlmpCtrlPdu.UserFields.MinorType, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("PDU_Length", "", 8, FormatValue(otaQlmpCtrlPdu.UserFields.PduLength, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Payload", "", otaQlmpCtrlPdu.UserFields.PayloadList.Count * 8, FormatValue(otaQlmpCtrlPdu.UserFields.PayloadList, otaQlmpCtrlPdu.UserFields.PayloadList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		OtaQlmpCtrlPdu otaQlmpCtrlPdu = (OtaQlmpCtrlPdu)packet;
		int num = -1;
		if (index == ++num)
		{
			otaQlmpCtrlPdu.UserFields.SeqNum = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			otaQlmpCtrlPdu.UserFields.LogsLostDrop = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			otaQlmpCtrlPdu.UserFields.ProdId = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			otaQlmpCtrlPdu.UserFields.LogId = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			otaQlmpCtrlPdu.UserFields.LogFormatLevel = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			otaQlmpCtrlPdu.UserFields.Timestamp = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			otaQlmpCtrlPdu.UserFields.Handle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			otaQlmpCtrlPdu.UserFields.MinorType = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			otaQlmpCtrlPdu.UserFields.PduLength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, otaQlmpCtrlPdu.UserFields.PayloadList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				otaQlmpCtrlPdu.UserFields.PayloadList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
