using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeApcfSolicitationUuidInfo : PacketInfoBase
{
	public override string Name => "Le Apcf Solicitation Uuid";

	public override string DisplayGroup => "Vendor Specific";

	public LeApcfSolicitationUuidInfo(LeApcfSolicitationUuid packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeApcfSolicitationUuid leApcfSolicitationUuid = (LeApcfSolicitationUuid)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("APCF_opcode", "Service Solicitation UUID", 8, FormatValue(leApcfSolicitationUuid.UserFields.ApcfOpcode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("APCF_Action", LeApcfSolicitationUuid.UserFieldsWrapper.ApcfActionInfo.ApcfActionToDescription(), 8, FormatValue(leApcfSolicitationUuid.UserFields.ApcfAction, 8), LeApcfSolicitationUuid.UserFieldsWrapper.ApcfActionInfo.ApcfActionToString(LeApcfSolicitationUuid.UserFieldsWrapper.ApcfActionInfo.ValueToApcfAction(leApcfSolicitationUuid.UserFields.ApcfAction)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("APCF_Filter_Index", "Filter index (0, max_filter-1)", 8, FormatValue(leApcfSolicitationUuid.UserFields.ApcfFilterIndex, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("APCF_UUID_Length", LeApcfSolicitationUuid.UserFieldsWrapper.ApcfUuidLengthInfo.ApcfUuidLengthToDescription(), 8, FormatValue(leApcfSolicitationUuid.UserFields.ApcfUuidLength, 8), LeApcfSolicitationUuid.UserFieldsWrapper.ApcfUuidLengthInfo.ApcfUuidLengthToString(LeApcfSolicitationUuid.UserFieldsWrapper.ApcfUuidLengthInfo.ValueToApcfUuidLength(leApcfSolicitationUuid.UserFields.ApcfUuidLength)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: true, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("APCF_UUID_AND_MASK", "The Solicitation UUID and Mask (16-bit, 32-bit, or 128-bit) to add to or delete from the list.", leApcfSolicitationUuid.UserFields.ApcfUuidAndMaskList.Count * 8, FormatValue(leApcfSolicitationUuid.UserFields.ApcfUuidAndMaskList, leApcfSolicitationUuid.UserFields.ApcfUuidAndMaskList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.LeftAlignedHex));
	}

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