using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FMHCI.Packets;

public class DefaultDataWriteInfo : PacketInfoBase
{
	public override string Name => "Default Data Write";

	public override string DisplayGroup => "Common Control";

	public DefaultDataWriteInfo(DefaultDataWrite packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		DefaultDataWrite defaultDataWrite = (DefaultDataWrite)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(defaultDataWrite.UserFields.Mode, 8), DefaultDataModeInfo.DefaultDataModeToString(DefaultDataModeInfo.ValueToDefaultDataMode(defaultDataWrite.UserFields.Mode)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Data Length", "Length of data field", 8, FormatValue(defaultDataWrite.UserFields.DataLength, 8), "", "", "F9", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Data", "Data to write", defaultDataWrite.UserFields.DataList.Count * 8, FormatValue(defaultDataWrite.UserFields.DataList, defaultDataWrite.UserFields.DataList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

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