using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class PinCodeRequestReplyInfo : PacketInfoBase
{
	public override string Name => "Pin Code Request Reply";

	public override string DisplayGroup => "Link Control";

	public PinCodeRequestReplyInfo(PinCodeRequestReply packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		PinCodeRequestReply pinCodeRequestReply = (PinCodeRequestReply)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("BD Address", "BD_ADDR of the Device which the PIN code is for.", 48, FormatValue(pinCodeRequestReply.UserFields.BdAddress, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("PIN_Code_Length", "The PIN code length specifics the length, in octets, of the PIN code to be used.", 8, FormatValue(pinCodeRequestReply.UserFields.PinCodeLength, 8), "", "01", "10", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Pin Code", "PIN Code for the device that is to be connecetd ", pinCodeRequestReply.UserFields.PinCodeList.Count * 8, FormatValue(pinCodeRequestReply.UserFields.PinCodeList, pinCodeRequestReply.UserFields.PinCodeList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		PinCodeRequestReply pinCodeRequestReply = (PinCodeRequestReply)packet;
		int num = -1;
		if (index == ++num)
		{
			pinCodeRequestReply.UserFields.BdAddress = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			pinCodeRequestReply.UserFields.PinCodeLength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, pinCodeRequestReply.UserFields.PinCodeList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				pinCodeRequestReply.UserFields.PinCodeList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
