using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeReadLocalP256PublicKeyCompleteInfo : PacketInfoBase
{
	public override string Name => "Le Read Local P256 Public Key Complete";

	public override string DisplayGroup => "LE Controller";

	public LeReadLocalP256PublicKeyCompleteInfo(LeReadLocalP256PublicKeyComplete packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeReadLocalP256PublicKeyComplete leReadLocalP256PublicKeyComplete = (LeReadLocalP256PublicKeyComplete)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Subevent_Code", "Subevent code for LE Read Local P-256 Public Key Complete event", 8, FormatValue(leReadLocalP256PublicKeyComplete.UserFields.SubeventCode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(leReadLocalP256PublicKeyComplete.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(leReadLocalP256PublicKeyComplete.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Local P-256 Public Key", "Local P-256 public key", leReadLocalP256PublicKeyComplete.UserFields.LocalP256PublicKeyList.Count * 8, FormatValue(leReadLocalP256PublicKeyComplete.UserFields.LocalP256PublicKeyList, leReadLocalP256PublicKeyComplete.UserFields.LocalP256PublicKeyList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeReadLocalP256PublicKeyComplete leReadLocalP256PublicKeyComplete = (LeReadLocalP256PublicKeyComplete)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubeventCode");
		}
		if (index == ++num)
		{
			leReadLocalP256PublicKeyComplete.UserFields.Status = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, leReadLocalP256PublicKeyComplete.UserFields.LocalP256PublicKeyList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				leReadLocalP256PublicKeyComplete.UserFields.LocalP256PublicKeyList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
