using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeMultiAdvtSetAdvtDataMultiInfo : PacketInfoBase
{
	public override string Name => "Le Multi Advt Set Advt Data Multi";

	public override string DisplayGroup => "Vendor Specific";

	public LeMultiAdvtSetAdvtDataMultiInfo(LeMultiAdvtSetAdvtDataMulti packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeMultiAdvtSetAdvtDataMulti leMultiAdvtSetAdvtDataMulti = (LeMultiAdvtSetAdvtDataMulti)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Multi_advt_opcode", "Set_Advt_Data_Multi_Sub_Cmd", 8, FormatValue(leMultiAdvtSetAdvtDataMulti.UserFields.MultiAdvtOpcode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Advertising_Data_Length", "The number of significant octets in the Advertising_Data", 8, FormatValue(leMultiAdvtSetAdvtDataMulti.UserFields.AdvertisingDataLength, 8), "", "00", "1F", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Advertising_Data", "31 octets of advertising data formatted as defined in BT Specification (ADVERTISING AND SCAN RESPONSE DATA FORMAT Section). All octets zero (default).", leMultiAdvtSetAdvtDataMulti.UserFields.AdvertisingDataList.Count * 8, FormatValue(leMultiAdvtSetAdvtDataMulti.UserFields.AdvertisingDataList, leMultiAdvtSetAdvtDataMulti.UserFields.AdvertisingDataList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.LeftAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Advertising_Instance", "Specifies the applicability of the above parameters to an instance.", 8, FormatValue(leMultiAdvtSetAdvtDataMulti.UserFields.AdvertisingInstance, 8), "", "01", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeMultiAdvtSetAdvtDataMulti leMultiAdvtSetAdvtDataMulti = (LeMultiAdvtSetAdvtDataMulti)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field MultiAdvtOpcode");
		}
		if (index == ++num)
		{
			leMultiAdvtSetAdvtDataMulti.UserFields.AdvertisingDataLength = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, leMultiAdvtSetAdvtDataMulti.UserFields.AdvertisingDataList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				leMultiAdvtSetAdvtDataMulti.UserFields.AdvertisingDataList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
		if (index == ++num)
		{
			leMultiAdvtSetAdvtDataMulti.UserFields.AdvertisingInstance = Convert.ToUInt32(value, 16);
		}
	}
}
