using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class AclDataInfo : PacketInfoBase
{
	public override string Name => "Acl Data";

	public override string DisplayGroup => "Data";

	public AclDataInfo(AclData packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		AclData aclData = (AclData)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Handle", "", 8, FormatValue(aclData.UserFields.Handle, 8), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Flags", "", 8, FormatValue(aclData.UserFields.Flags, 8), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Data Length", "", 16, FormatValue(aclData.UserFields.DataLength, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Data", "", aclData.UserFields.DataList.Count * 8, FormatValue(aclData.UserFields.DataList, aclData.UserFields.DataList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

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