using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeGenerateDhkeyV2Info : PacketInfoBase
{
	public override string Name => "Le Generate Dhkey V2";

	public override string DisplayGroup => "LE Controller";

	public LeGenerateDhkeyV2Info(LeGenerateDhkeyV2 packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeGenerateDhkeyV2 leGenerateDhkeyV = (LeGenerateDhkeyV2)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Remote_P-256_Public_Key", "The remote P-256 public key: X, Y format Octets 31-0: X co-ordinate Octets 63-32: Y co-ordinate", leGenerateDhkeyV.UserFields.RemoteP256PublicKeyList.Count * 8, FormatValue(leGenerateDhkeyV.UserFields.RemoteP256PublicKeyList, leGenerateDhkeyV.UserFields.RemoteP256PublicKeyList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Key_Type", "Use generated private key or debug private key.\r\n\r\n" + LeGenerateDhkeyV2.UserFieldsWrapper.KeyTypeInfo.KeyTypeToDescription(), 8, FormatValue(leGenerateDhkeyV.UserFields.KeyType, 8), LeGenerateDhkeyV2.UserFieldsWrapper.KeyTypeInfo.KeyTypeToString(LeGenerateDhkeyV2.UserFieldsWrapper.KeyTypeInfo.ValueToKeyType(leGenerateDhkeyV.UserFields.KeyType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

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