using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FMHCI.Packets;

public class DefaultDataReadInfo : PacketInfoBase
{
	public override string Name => "Default Data Read";

	public override string DisplayGroup => "Common Control";

	public DefaultDataReadInfo(DefaultDataRead packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		DefaultDataRead defaultDataRead = (DefaultDataRead)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Mode", "Mode for which default data needs to be read\r\n\r\n" + DefaultDataModeInfo.DefaultDataModeToDescription(), 8, FormatValue(defaultDataRead.UserFields.Mode, 8), DefaultDataModeInfo.DefaultDataModeToString(DefaultDataModeInfo.ValueToDefaultDataMode(defaultDataRead.UserFields.Mode)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Length", "Length of the default data to read", 8, FormatValue(defaultDataRead.UserFields.Length, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Parameter Length", "Length of the default data command read parameters in bytes", 8, FormatValue(defaultDataRead.UserFields.ParameterLength, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Parameter", "", defaultDataRead.UserFields.ParameterList.Count * 8, FormatValue(defaultDataRead.UserFields.ParameterList, defaultDataRead.UserFields.ParameterList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

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