using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FM.Packets;

public class ReadI2cResponseInfo : PacketInfoBase
{
	public override string Name => "Read I2c Response";

	public override string DisplayGroup => "Test";

	public ReadI2cResponseInfo(ReadI2cResponse packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		ReadI2cResponse readI2cResponse = (ReadI2cResponse)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Length", "Length of the data received", 8, FormatValue(readI2cResponse.UserFields.Length, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: true, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Data", "Data received", readI2cResponse.UserFields.DataList.Count * 8, FormatValue(readI2cResponse.UserFields.DataList, readI2cResponse.UserFields.DataList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

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