using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeApcfManfDataInfo : PacketInfoBase
{
	public override string Name => "Le Apcf Manf Data";

	public override string DisplayGroup => "Vendor Specific";

	public LeApcfManfDataInfo(LeApcfManfData packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeApcfManfData leApcfManfData = (LeApcfManfData)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("APCF_opcode", "Manufacturer Data", 8, FormatValue(leApcfManfData.UserFields.ApcfOpcode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("APCF_Action", LeApcfManfData.UserFieldsWrapper.ApcfActionInfo.ApcfActionToDescription(), 8, FormatValue(leApcfManfData.UserFields.ApcfAction, 8), LeApcfManfData.UserFieldsWrapper.ApcfActionInfo.ApcfActionToString(LeApcfManfData.UserFieldsWrapper.ApcfActionInfo.ValueToApcfAction(leApcfManfData.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(leApcfManfData.UserFields.ApcfFilterIndex, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("APCF_Manufacturer_Data_Length", "Manufacturer data length.", 8, FormatValue(leApcfManfData.UserFields.ApcfManufacturerDataLength, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: true, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("APCF_Manufacturer_Data", "A character string for manufacturer data. Notes: i) Currently the max number of characters in a manufacturer data string is 29, ii) N/A when action = “Clear”", leApcfManfData.UserFields.ApcfManufacturerDataList.Count * 8, FormatValue(leApcfManfData.UserFields.ApcfManufacturerDataList, leApcfManfData.UserFields.ApcfManufacturerDataList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.LeftAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("APCF_Manufacturer_Data_Mask_Length", "This should be set to the same value as APCF_Manufacturer_Data_Length.", 8, FormatValue(leApcfManfData.UserFields.ApcfManufacturerDataMaskLength, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: true, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("APCF_Manufacturer_Data_Mask", "The manufacture data mask to add to the list. It should have the same length as APCF_Manufacturer_Data.", leApcfManfData.UserFields.ApcfManufacturerDataMaskList.Count * 8, FormatValue(leApcfManfData.UserFields.ApcfManufacturerDataMaskList, leApcfManfData.UserFields.ApcfManufacturerDataMaskList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.LeftAlignedHex));
	}

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