using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeEncryptInfo : PacketInfoBase
{
	public override string Name => "Le Encrypt";

	public override string DisplayGroup => "LE Controller";

	public LeEncryptInfo(LeEncrypt packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeEncrypt leEncrypt = (LeEncrypt)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("key", "128 bit key for the encryption of the data given in the command. The most significant octet of the key corresponds to key[0] using the notation specified in FIPS 197", leEncrypt.UserFields.KeyList.Count * 8, FormatValue(leEncrypt.UserFields.KeyList, leEncrypt.UserFields.KeyList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Plaintext_Data", "128 bit data block that is requested to be encrypted. The most significant octet of the PlainText_Data corresponds to in[0] using the notation specified in FIPS 197", leEncrypt.UserFields.PlaintextDataList.Count * 8, FormatValue(leEncrypt.UserFields.PlaintextDataList, leEncrypt.UserFields.PlaintextDataList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeEncrypt leEncrypt = (LeEncrypt)packet;
		int num = -1;
		if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, leEncrypt.UserFields.KeyList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				leEncrypt.UserFields.KeyList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
		if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, leEncrypt.UserFields.PlaintextDataList.Count);
			int num3 = 0;
			while (value.Length > 0)
			{
				string value3 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				leEncrypt.UserFields.PlaintextDataList[num3] = Convert.ToUInt32(value3, 16);
				num3++;
			}
		}
	}
}
